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...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

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
incrementing numbers   Message List  
Reply | Forward Message #111 of 221 |
I have a set of files that need to have a number assigned to $3 for
each record, but if the record has the same value in $2, the value in
$3 must stay the same also.
Here is what it should end up looking like:
06/04/2004|898|1|
06/04/2004|898|1|
06/04/2004|898|1|
06/04/2004|899|2|
06/04/2004|899|2|
06/04/2004|900|3|
06/04/2004|901|4|
06/04/2004|902|5|
06/05/2004|903|6|
06/05/2004|903|6|
06/05/2004|904|7|
06/05/2004|904|7|
06/05/2004|904|7|

I can reset the counter for each new $2, with:
BEGIN {FS="|"; OFS="|"; last="";}
{
if ($2 != last) { line = 0; last = $2; }
line++; $3 =line;
print $0
}
but I can't figure out how to keep it the same if the $2 is the same
as the previous one.

Can anyone help me?






Tue Sep 7, 2004 9:20 pm

d_godfrey2000
Online Now Online Now
Send Email Send Email

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

I have a set of files that need to have a number assigned to $3 for each record, but if the record has the same value in $2, the value in $3 must stay the same...
d_godfrey2000
Online Now Send Email
Sep 7, 2004
9:21 pm
Advanced

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