Unix / Linux Shell: Parse Text CVS File Separator By Field

To parse a text CSV file in Unix/Linux shell, you can use the awk command. Here’s an example that separates the fields by comma (‘,’) and prints the values of each field:

 
awk -F',' '{ print $1, $2, $3, $4 }' input.csv

In this example, -F',' sets the field separator to a comma, and $1, $2, $3, $4 represent the values of the first, second, third, and fourth fields, respectively.

You can also use the cut command to parse a CSV file:

 
cut -d',' -f1,2,3,4 input.csv

In this example, -d',' sets the delimiter to a comma and -f1,2,3,4 selects the first, second, third, and fourth fields.

(Ambien online)

Leave a Comment