How to extract one column of a csv file How to extract one column of a csv file bash bash

How to extract one column of a csv file


You could use awk for this. Change '$2' to the nth column you want.

awk -F "\"*,\"*" '{print $2}' textfile.csv


yes. cat mycsv.csv | cut -d ',' -f3 will print 3rd column.


The simplest way I was able to get this done was to just use csvtool. I had other use cases as well to use csvtool and it can handle the quotes or delimiters appropriately if they appear within the column data itself.

csvtool format '%(2)\n' input.csv

Replacing 2 with the column number will effectively extract the column data you are looking for.