Printing column separated by comma using Awk command line

user3364728 picture user3364728 · Nov 10, 2014 · Viewed 178.2k times · Source

I have a problem here. I have to print a column in a text file using awk. However, the columns are not separated by spaces at all, only using a single comma. Looks something like this:

column1,column2,column3,column4,column5,column6

How would I print out 3rd column using awk?

Answer

SMA picture SMA · Nov 10, 2014

Try:

awk -F',' '{print $3}' myfile.txt

Here in -F you are saying to awk that use "," as field separator.