Get the nth element of a csv file in Linux

You have a file called input.csv file containing

fname, lname, email, postcode

john,smith,johnsmith@example.com,4000

jane,doe,janedoe@example.com,4112

 

and you want to get the lname element

while IFS=',' read -r a1 a2 a3 a4 
do 
echo "$a2" >> lname.csv
done < input.csv

Source: https://unix.stackexchange.com/questions/106047/extract-the-4th-column-from-a-csv-file-using-unix-command

Leave a Reply

Your email address will not be published. Required fields are marked *