Computer Scientist, Graduate Student, and Geek

Tag: awk

Parse a CSV File Using Awk

July 06, 2011

To perform text processing on a CSV file row-by-row, you can use awk. A single row can be split into columns using the split command. The data can be output as desired using the print command. The example below outputs the 1st and 3rd columns of a CSV file:

cat myfile.csv | awk '{ split($0,a,","); print a[1]","a[3]; }'

It is important to note that awk uses one-based array indexing (not zero-based).

Categories: Uncategorized

Tags: awk