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 to share photos of your group with the world? 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
Re: [Geeks that Gawk] incrementing numbers   Message List  
Reply | Forward Message #112 of 221 |

In order to achieve what you give in your example, I would suggest this:

BEGIN {FS="|"; OFS="|"; last="";}
{
if ($2 != last) {
last = $2
line++;
}
$3 =line;
print $0
}

I haven't actually tested this code, but give it a try. Part of the problem
with the old code was that it was re-setting line to zero every time the 2nd
field was the same as the previous. And then, the "line++" part was outside
the block that was controlled by the if statement, so that it was getting
incremented for every record.

--Albert

Albert Bickford

----- Original Message -----





This message has been scanned for viruses by the VEI Internet
Automatic Email Spam and Virus Scanner, and is believed to be free of spam or
viruses.
Please report spam to spamtrap@.... If you would like 98.9 % spam blocked
from your
E-mail then go to VEI Internet for details. Anti-spam/Anti-virus is FREE with
every account.


http://www.vei.net/
mailtospamtrap@...

[Non-text portions of this message have been removed]




Wed Sep 8, 2004 11:44 am

albert_bickford
Offline Offline
Send Email Send Email

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

In order to achieve what you give in your example, I would suggest this: BEGIN {FS="|"; OFS="|"; last="";} { if ($2 != last) { last = $2 line++; } $3 =line; ...
Albert Bickford
albert_bickford
Offline Send Email
Sep 9, 2004
1:13 am

... Thanks Albert! Your solution works great. I did have to change it to fit my actual file format - here are a few lines (bear with me - I'm showing the REST...
Don Godfrey
d_godfrey2000
Online Now Send Email
Sep 9, 2004
6:29 pm

From what you've said below, it sounds like you've handled things more or less the way I would have done it. Perhaps there is a more elegant way, but one of...
Albert Bickford
albert_bickford
Offline Send Email
Sep 11, 2004
12:48 pm

... The reason I was trying to do it in one script, was for speed - I'm processing about 1 million records each time I run it, and doing quite a few other...
Don Godfrey
d_godfrey2000
Online Now Send Email
Sep 11, 2004
4:54 pm

... few ... I'm afraid I don't know that. You might have to do some testing to find out. I was speaking before from the perspective of optimizing development...
Albert Bickford
albert_bickford
Offline Send Email
Sep 12, 2004
1:19 pm

With help of someone, for my immediate need, I was able to do the following and was able to process the files. #! /bin/bash for ( j = 1; j < 125; j++ ); do ...
Jagdish Shah
shahjb40
Offline Send Email
Sep 13, 2004
5:36 pm
Advanced

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