Ha, Just a few minutes late, and although your question is lacking info, and despite what I wrote you should do it in python, I decide that for the challenge I'll do it in BASH (and NOT AWK).
oz123@debian:~$ cat csvfile.csv
1,2,3
4,5,6
7,8,9
oz123@debian:~$ cat csvfile.csv | ( while
> read line;
> do
> VAR1=`echo $line | cut -d "," -f1` ;
> VAR2=`echo $line | cut -d "," -f2` ;
> echo $VAR1+$VAR2
> echo $VAR1+$VAR2 | bc
>
> done;
>
> )
1+2
3
4+5
9
7+8
15
oz123@debian:~$
OK, My first solution is indeed UGLY, and computationally expansive. Here is a nicer solution:
oldifs=$IFS; export IFS=","; cat csvfile.csv | while read -a line; do echo ${line[2]}+${line[1]} | bc; done
the -a
flag turns the lines into arrays. The IFS
is The Internal Field Separator (see man bash
).