The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 01:43 PM
Retrieve 5th Field to Last Field !! jobbyjoseph UNIX for Dummies Questions & Answers 3 05-16-2007 03:20 AM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 05:39 AM
TTL field??? solvman UNIX for Advanced & Expert Users 11 10-12-2001 12:54 AM
awk sub-field? kristy UNIX for Dummies Questions & Answers 2 10-05-2001 04:07 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-14-2005
azekry azekry is offline
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
  #2 (permalink)  
Old 11-14-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
nawk '$1 != prev {cnt++; prev=$1}{print cnt, $0}' myFile.txt
  #3 (permalink)  
Old 11-14-2005
azekry azekry is offline
Registered User
  
 

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


Appreciate your help
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0