Read the file with Gawk a line at a time. Set comma as the field separator.
On each line, look at the second field. If it is an account number that
you haven't seen before, then (i.e., if $2 <> PrevAcctNum)
If this isn't the first account you've seen:
output the line "NUMBER OF ACCTS WITH CODE" PrevAcctNum ": "
AcctCount
reset AcctCount to zero
output the header line: "ACCTS WITH CODE " $2
Remember what the current account number is (for comparison with the
next line): PrevAcctNum = $2
Then, for each line:
print the first field ($1)
increment the AcctCount
And (important), at the end of the file, output the line "NUMBER OF
ACCTS WITH CODE" PrevAcctNum ": " AcctCount for the last group.
This doesn't cover all the details, but it is the general idea. I hope
you can take it from there.
Albert
Femi George [ MTN - Golden Plaza ] wrote:
> i have the following file;
>
> 12345,89
> 78777,89
> 56789,40
> 18978,40
> 98864,40
> 21378,41
>
> i want to create a different file like this;
>
> ACCTS WITH CODE 89
> 12345
> 78777
> NUMBER OF ACCTS WITH CODE 89: 2
> ACCTS WITH CODE 40
> 56789
> 18978
> 98864
> NUMBER OF ACCTS WITH CODE 40: 3
> ACCTS WITH CODE 41
> 21378
> NUMBER OF ACCTS WITH CODE 41: 1
>
> how can i do this please?
> thanks
>
> http://www.mtnonline.com/contact/disclaimer.asp
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
>
>