reno
1
Hi all
I am trying to scan a file that has 3 columns:
red blue 123351
red blue 848655
red blue 126354
red blue 023158
black white 654896
red blue 650884
I want an output that sums the rows that have matching columns 1 and 2 :wall:
red blue has 5 entries
black white has 1 entry
Thanks
Can you show us what you have tried so far?
reno
3
Hello
Well I am not clued up on the subject. So I first tried to get only the columns I am interested in
awk -F " " '{print $1 $2}' datafile > ouput
I am thinking to use a while loop that counts identical lines in the "output" file.
Thanks
Reno
---------- Post updated at 05:36 PM ---------- Previous update was at 05:06 PM ----------
Ok, I think I managed to pipe it to uniq -c
this gives me a count of all unique entries but I noticed that if I have a file that looks like that:
red blue 123351
red blue 848655
red blue 126354
red blue 023158
black white 654896
red blue 650884
the output is
4 red blue
1 black white
1 red blue
somehow I d like to have
5 red blue
1 black white
I ll keep digging!
Reno
Thanks
Reno
drl
4
Hi.
Suppose you sorted it first ... cheers, drl
rdcwayx
5
$ awk '{a[$1 FS $2]++}END{for (i in a) print a,i}' infile
5 red blue
1 black white
1 Like