bash method to remove last 4 columns from csv file

后端 未结 8 1328
后悔当初
后悔当初 2021-01-01 21:48

Is there a way to use bash to remove the last four columns for some input CSV file? The last four columns can have fields that vary in length from line to line so it is not

8条回答
  •  渐次进展
    2021-01-01 22:42

    cat data.csv | rev | cut -d, -f-5 | rev
    

    rev reverses the lines, so it doesn't matter if all the rows have the same number of columns, it will always remove the last 4. This only works if the last 4 columns don't contain any commas themselves.

提交回复
热议问题