Single command oneliner :)
awk -F, '{if(NR==1)next;total+=$2}END{print total}' shopping.csv
if(NR==1)
next
total+=$2
total
Repeat above for all the lines
END{print total}
I used to hate awk scripts - they are so awkward to read... But awk embeds so many shell utilities that it's really worth to learn it ;)
Or a shorter (less verbose) version:
awk -F, 'FNR>1{total+=$2}END{print total}' shopping.csv
awk -F, '{sum+=$2}END{print sum}' shopping.csv
cut -d, -f2 a.txt|paste -s -d+|bc
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Single command oneliner :)
if(NR==1)
// if Number_of_Row is 1, i.e. if it's the first rownext
// continue, i.e. skip the row and go to the next onetotal+=$2
// create a global variabletotal
if not exists (initialized with '0') and add 2nd column value to it.Repeat above for all the lines
END{print total}
// print the global variabletotal
to the console.I used to hate awk scripts - they are so awkward to read... But awk embeds so many shell utilities that it's really worth to learn it ;)
Or a shorter (less verbose) version: