How to remove the first two columns from a CSV file using cut
I need to remove the first two columns in a CSV file that was generated from Mockaroo, but I had to create a date
and time
field in it as well, to get the correct format for a date field(s), as it didn't let me completely generate what I needed.
So, put the date and time fields first in the CSV file to make it easier to remove.
Code or Examples
In the article how to remove the first two columns in a file using shell (awk, sed, whatever), the answer by sampson-chen did exactly what I wanted using cut.
You can do it with cut:
cut -d " " -f 3- input_filename > output_filename
Explanation:
cut
: invoke the cut command-d " "
: use a single space as the delimiter (cut uses TAB by default)-f
: specify fields to keep3-
: all the fields starting with field 3input_filename
: use this file as the input> output_filename
: write the output to this file.
I will need to do something like this, as I have a csv file, so need a comma for the delimiter:
cut -d "," -f 3- input_filename > output_filename
Tried it and it worked like a charm.