0
Thanks

A few words of thanks would be greatly appreciated.

Linux - Aggregate data and count lines



I have a file containing:
A;1;C;X;123456  
A;1;C;X;234567  
A;1;C;Y;345678  
A;2;D;X;456789  
B;1;D;X;567890  
B;1;D;X;567891  
B;1;D;X;567892 

And I would like to aggregate the data and count lines to get this:
2;A;1;C;X  
1;A;1;C;Y  
1;A;2;D;X  
3;B;1;D;X 


Occurrences will be based on the first column.
How to achieve the following using AWK.
Try this:
2;A;1;C;X  
1;A;1;C;Y  
1;A;2;D;X  
3;B;1;D;X  

$ cat brol  
A;1;C;X;123456 
A;1;C;X;234567 
A;1;C;Y;345678 
A;2;D;X;456789 
B;1;D;X;567890 
B;1;D;X;567891 
B;1;D;X;567892 

$ uniq -c -w7 brol | cut -d';' -f 1-4 
      2 A;1;C;X 
      1 A;1;C;Y 
      1 A;2;D;X 
      3 B;1;D;X 

$


Thanks to zipe31 for this tip.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Linux - Aggregate data and count lines », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!