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
Make variable length record a fixed length jclanc8 Shell Programming and Scripting 3 10-03-2009 09:24 PM
get part of file with unique & non-unique string andrewsc Shell Programming and Scripting 5 09-17-2009 04:43 PM
Unique batch and sequence creation gehlnar Shell Programming and Scripting 3 02-04-2009 05:32 AM
ksh scripting: Extract 1 most recent record for unique key OPTIMUS_prime Shell Programming and Scripting 2 10-31-2008 09:44 AM
Split a record ( in a row) and make it as new row kottursamy Shell Programming and Scripting 2 08-12-2008 10:28 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 3 Weeks Ago
gehlnar gehlnar is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
Managing sequence to make unique record

Hi Everyone,

Using shell script i am getting final file as attached below. In this 4th column value should be unique using any sequence.
for instance I've 1_13020_SSGM which is appearing 6 times in file and i should change it like 1_13020_SSGM_1,1_13020_SSGM_2,....1_13020_SSGM_6.
Can someone please provide some idea on this?
Input file
05112009,601,Excel,1_13020_DWS,1,999001
05112009,601,Excel,1_11020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_SSGM,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_13020_NEWE,1,999001
05112009,601,Excel,1_11020_NEWE,1,999001
05112009,601,Excel,1_11020_DWS,1,999001
05112009,601,Excel,1_11020_DWS,1,999001
05112009,601,Excel,1_11020_DWS,1,999001
05112009,601,Excel,1_11020_DWS,1,999001
Output file
05112009,601,Excel,1_13020_DWS_1,1,999001
05112009,601,Excel,1_11020_SSGM_1,1,999001
05112009,601,Excel,1_13020_SSGM_1,1,999001
05112009,601,Excel,1_13020_SSGM_2,1,999001
05112009,601,Excel,1_13020_SSGM_3,1,999001
05112009,601,Excel,1_13020_SSGM_4,1,999001
05112009,601,Excel,1_13020_SSGM_5,1,999001
05112009,601,Excel,1_13020_SSGM_6,1,999001
05112009,601,Excel,1_13020_NEWE_1,1,999001
05112009,601,Excel,1_13020_NEWE_2,1,999001
05112009,601,Excel,1_13020_NEWE_3,1,999001
05112009,601,Excel,1_13020_NEWE_4,1,999001
05112009,601,Excel,1_13020_NEWE_5,1,999001
05112009,601,Excel,1_11020_NEWE_1,1,999001
05112009,601,Excel,1_11020_DWS_1,1,999001
05112009,601,Excel,1_11020_DWS_2,1,999001
05112009,601,Excel,1_11020_DWS_3,1,999001
05112009,601,Excel,1_11020_DWS_4,1,999001

Thanks in advance.
  #2 (permalink)  
Old 3 Weeks Ago
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,431
Code:
awk '{FS=OFS=",";$4=$4"_"++a[$4]}1' file
Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.
  #3 (permalink)  
Old 3 Weeks Ago
gehlnar gehlnar is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
Hi Danmero,

Thank you very much. It gives me exact result.

Regards,
gehlnar
  #4 (permalink)  
Old 3 Weeks Ago
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 453
Perl solution...

Code:
perl -e 'while(<STDIN>)  {  @a= split(/,/,$_); print "$a[0],$a[1],$a[2],$a[3]_" . ++$hash{$a[3]}. " ,$a[4],$a[5]"; }' < t
t is the input file..
  #5 (permalink)  
Old 2 Weeks Ago
gehlnar gehlnar is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
Hi Geek,

Thanks for your input , this will help me if i use perl script.

Regards,
gehlnar
Reply

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 12:32 AM.


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