How can I write a linux command to delete the last column of tab-delimited csv?
Example input
aaa bbb ccc ddd
111 222 333 444
Expected output
aaa bbb ccc
111 222 333
Advertisement
Answer
It is easy to remove the fist field instead of the last. So we reverse the content, remove the first field, and then revers it again.
Here is an example for a “CSV”
rev file1 | cut -d "," -f 2- | rev
Replace the “file1” and the “,” with your file name and the delimiter accordingly.