Parsing a comma seperated file with shell

Thursday, Sep 24, 2009

Make sure you read the file line by line correctly using a while read construct.

while read -r line
    set -- $line
    echo $4 >> $1.mdwn
    echo "$line"
done < "m4.2_testplan.csv"

Use set to parse the CSV. It doesn’t do a perfect job, but it’s usually ok.

In the above example I’m splitting a test description from column 4 into a file named after the id from column 1.