The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reindex or re-increment last field of txt file. silenthands Shell Programming and Scripting 2 11-08-2007 10:43 AM
Retrieve 5th Field to Last Field !! jobbyjoseph UNIX for Dummies Questions & Answers 3 05-16-2007 12:20 AM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 02:39 AM
TTL field??? solvman UNIX for Advanced & Expert Users 11 10-11-2001 09:54 PM
awk sub-field? kristy UNIX for Dummies Questions & Answers 2 10-05-2001 01:07 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-14-2005
Registered User
 

Join Date: Nov 2005
Posts: 2
add increment field when first field changes

Hi
I have a file that looks like the following:

Name1 aaa bbbb
Name1 ffd hhghg
Name1 dffg ghhhh
Name2 rtrt dfff
Name2 rrtfr tgtt
Name2 dsddf gfggf
Name2 ffffg gfgf
NAme3 fdff ghhgh

Is it possible to format it so that a number increment field is added whenever the first field in a record changes. like that

1 Name1 aaa bbbb
1 Name1 ffd hhghg
1 Name1 dffg ghhhh
2 Name2 rtrt dfff
2 Name2 rrtfr tgtt
2 Name2 dsddf gfggf
2 Name2 ffffg gfgf

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 11-14-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Code:
nawk '$1 != prev {cnt++; prev=$1}{print cnt, $0}' myFile.txt
Reply With Quote
  #3  
Old 11-14-2005
Registered User
 

Join Date: Nov 2005
Posts: 2
Thanks so much.
This works great.


Appreciate your help
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0