Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk - replacing field content of all records in a file 1

Status
Not open for further replies.

waipahu

Technical User
Oct 7, 2007
2
US
I'm not an experienced programmer. I decidied to teach myself awk. I have a file with a list of records that has several fields and i'm trying to change the value of 1 field with a number that increases for each successive record; ie - record 1 $4 = 249, record 2 $4 =250, record 3 $4 =251.....etc. below is one of my many iterations. I've tried including the 'next' and 'continue' statements but nothing works. I can not get the program to increment to the next record with out the 'for' statement completing it's cycle for each record.

BEGIN { FS="[/:,=]" }

{ for ( lno=249; lno<=259 ; lno++ )

$4==lno

print $0 }

END { print NR }
 
What about this ?
BEGIN { FS="[/:,=]"; lno=249 }
{ $4=lno++; print $0 }
END { print NR }

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This is great! Mahalo for a quick response.

Is there a way where i can perserve the FS's : , and = in the printing of each record? In other words, i like to be able to print the field separaters as part of each record.

waipahu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top