bash method to remove last 4 columns from csv file

2019-04-06 09:35发布

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 sufficient to just delete a certain number of characters from the end of each row.

标签: bash csv sed awk cut
7条回答
淡お忘
2楼-- · 2019-04-06 10:00

You can use cut for this if you know the number of columns. For example, if your file has 9 columns, and comma is your delimiter:

cut -d',' -f -5

However, this assumes the data in your csv file does not contain any commas. cut will interpret commas inside of quotes as delimiters also.

查看更多
登录 后发表回答