Bash Read Comma Separated CSV File on Linux / Unix

Originally published at: https://www.cyberciti.biz/faq/unix-linux-bash-read-comma-separated-cvsfile/

How do I read comma separated CVS file under UNIX / Linux / BSD / MacOS bash script? My sample file is as follows
FirstName LastName,DOB,SSN,Telephone,Status
How can I parse a CSV file in Bash?

The awk program is a great tool for parsing CSV files. You can use it within a bash script.
For example, this line would print the first and second fields in a CSV file:

awk -F, '{ print $1,$2 }' filename.csv
1 Like

Another solution:

sed -e 's@,@ @g' filename.csv > filename.fields_space_separated