How to get the first column of every line from a CSV file? How to get the first column of every line from a CSV file? shell shell

How to get the first column of every line from a CSV file?


Try this:

 awk -F"," '{print $1}' data.txt

It will split each input line in the file data.txt into different fields based on , character (as specified with the -F) and print the first field (column) to stdout.


echo "a,b,c" | cut -d',' -f1 > newFile