Search the web
Sign In
New User? Sign Up
geeksthatgawk · for GNU Awk questions & discussions
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
creating a new file from old one using awk   Message List  
Reply | Forward Message #215 of 221 |
Re: [Geeks that Gawk] creating a new file from old one using awk

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
>
>
>
>
>
>
>
>
>
>
>
>



Fri Sep 22, 2006 1:29 am

albert_bickford
Offline Offline
Send Email Send Email

Forward
Message #215 of 221 |
Expand Messages Author Sort by Date

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 ...
Femi George [ MTN - G...
gnuts4lunch
Offline Send Email
Sep 22, 2006
12:41 am

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...
Albert Bickford
albert_bickford
Offline Send Email
Sep 22, 2006
1:37 am

The algorithm below works best if the file is already pre-sorted based on the Account Code, so using gawk win32 and gsort win32... assume test.txt contains: ...
Ambrosio Berdijo
aberdijo
Offline Send Email
Sep 22, 2006
2:00 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help