SyntaxHighlighter JS

2013-01-20

Handling CSV in Unix

Sample Problem:
Add the values of column 2 and column 4 from a comma separated value (CSV) file.

Solution:
awk -F, '{print $2" plus "$4" is "$2+$4}' thefile.csv

Assuming thefile.csv contains
5,10,15,20
2,4,6,8

This will print out

10 plus 20 is 30
4 plus 8 is 12

No comments:

Post a Comment