How to split CSV file by Column values into multiple files on a Mac? awk

unix

HELP!!!
Trying to split a csv file admin_bids_view.csv into multiple files. The CSV has 2000 rows and 7 columns. I would like a new file per ID number in column 1.

Example data below:

enter image description here

Have tried awk -F\| '{print>$1}' admin_bids_view.csv

But the below is being returned.

awk: can't open file admin_bids_view.csv
source line number 1

Please can someone point me in the right direction?

Thank you.

Best Answer

Your approach would mostly work, although you'd end up with column A in the output file, which may not be what you want. Here's another approach that doesn't put column A in the output file:

awk -F, '{outfile=($1 ".csv") ; print substr($0,index($0,$2)) >>outfile ; close(outfile)}' <name_of_input_file

You said "CSV", so use a comma as the field separator.