Manipulate a CSV File

Hello,

How do i manipulate .csv file to this format?

Thank you very much.

Source:

john,5
marco,7
john,4
paul,3
marco,8

Output:

john,9
marco,15
paul,3
$ awk -F, '{ A[$1]+=$2 } END { OFS=","; for (x in A) print x,A[x]; }' input >output
paul,3
john,9
marco,15

What have you tried so far?

Hi,

it gives an error on centos

What is the error message? It works here on CentOS 6.5:

$ cat input
john,5
marco,7
john,4
paul,3
marco,8
$ awk -F, '{ A[$1]+=$2 } END { OFS=","; for (x in A) print x,A[x]; }' input
paul,3
john,9
marco,15
$ cat /etc/centos-release
CentOS release 6.5 (Final)
$ uname -a
Linux xxxxx 2.6.32-431.3.1.el6.i686 #1 SMP Fri Jan 3 18:53:30 UTC 2014 i686 i686 i386 GNU/Linux
$ type awk
awk is a tracked alias for /bin/awk
2 Likes

ok its works now :slight_smile: thank you very much.