How to Rename when duplicate found?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Rename when duplicate found?
# 1  
Old 06-17-2013
How to Rename when duplicate found?

Hi ,

i need to check the file , if 2 duplicated Values then rename the second duplicated value and save it on the same file, if 3 duplicated Values then rename the Second and Thired and save it on the same file , SOME TIME THERE IS NO DUPLICATE , as below



3100.2.142.11=360
3100.2.134.13= 0 è indicates start of Bundle 1 information
3100.2.124.1= Time_pre
3100.2.124.9= Quantity
3100.2.124.3=46
3100.2.124.8= 50
3100.2.124.2= 4
3100.2.124.6= 30/12/2014 23:00:00
3100.2.134.14= 0 è indicates end of Bundle 1 information
3100.2.134.4=1
3100.2.134.13= 0 è indicates start of Bundle 2 information
3100.2.124.1=Promo_pre
3100.2.124.9=Money
3100.2.124.3=500
3100.2.124.8=600
3100.2.124.2=100
3100.2.124.6=30/11/2013 22:00:00
3100.2.134.14=0 è indicates end of Bundle 2 information
3100.2.134.2=1
3100.2.134.13= 0 è indicates start of Bundle 3 information
3100.2.124.1=default_balance
3100.2.124.9=Money
3100.2.124.3=20000
3100.2.124.8=20000
3100.2.140.4=360
3100.2.124.2=0
3100.2.134.14= 0 è indicates end of Bundle 3 information


the Result should be like below ,

3100.2.142.11=360
3100.2.134.13= 0 è indicates start of Bundle 1 information
3100.2.124.1= Time_pre
3100.2.124.9= Quantity
3100.2.124.3=46
3100.2.124.8= 50
3100.2.124.2= 4
3100.2.124.6= 30/12/2014 23:00:00
3100.2.134.14= 0 è indicates end of Bundle 1 information
3100.2.134.4=1
3100.2.134.13.ADD1= 0 è indicates start of Bundle 2 information
3100.2.124.1.ADD1=Promo_pre
3100.2.124.9.ADD1=Money
3100.2.124.3.ADD1=500
3100.2.124.8.ADD1=600
3100.2.124.2.ADD1=100
3100.2.124.6.ADD1=30/11/2013 22:00:00
3100.2.134.14.ADD1=0 è indicates end of Bundle 2 information
3100.2.134.2=1
3100.2.134.13.ADD2= 0 è indicates start of Bundle 3 information
3100.2.124.1.ADD2=default_balance
3100.2.124.9.ADD2=Money
3100.2.124.3.ADD2=20000
3100.2.124.8.ADD2=20000
3100.2.140.4=360
3100.2.124.2.ADD2=0

3100.2.134.14.ADD2= 0 è indicates end of Bundle 3 information

Last edited by OTNA; 06-17-2013 at 05:52 AM..
# 2  
Old 06-17-2013
Please use code tags for code and data sample.

try

Code:
awk -F "=" '{if(!A[$1]){print }else{print $1".ADD"A[$1] FS $2}}{A[$1]++}' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 06-17-2013
Try also
Code:
awk -F= 'A[$1]  {$2=".ADD"A[$1] FS $2}
         ++A[$1] 
        ' OFS="" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies

2. UNIX for Dummies Questions & Answers

Using rename

I want to rename files Files show like this 1977SSD_rsdtst.pdf 1976SDP_rstdtsr.pdf 1943FDT_rstdsrt.pdf 1996DFF_stdstrd.pdf I want to introduce _ after the year, and move the characters to the end to get 1977_rsdtst_SSD.pdf 1976_rstdtsr_SDP.pdf 1943_rstdsrt_FDT.pdf... (4 Replies)
Discussion started by: kristinu
4 Replies

3. Shell Programming and Scripting

If first pattern is found, look for second pattern. If second pattern not found, delete line

I had a spot of trouble coming up with a title, hopefully you'll understand once you read my problem... :) I have the output of an ldapsearch that looks like this: dn: cn=sam,ou=company,o=com uidNumber: 7174 gidNumber: 49563 homeDirectory: /home/sam loginshell: /bin/bash uid: sam... (2 Replies)
Discussion started by: samgoober
2 Replies

4. Shell Programming and Scripting

Cant get awk 1liner to remove duplicate lines from Delimited file, get "event not found" error..help

Hi, I am on a Solaris8 machine If someone can help me with adjusting this awk 1 liner (turning it into a real awkscript) to get by this "event not found error" ...or Present Perl solution code that works for Perl5.8 in the csh shell ...that would be great. ****************** ... (3 Replies)
Discussion started by: andy b
3 Replies

5. UNIX for Dummies Questions & Answers

look for specific values in a file and rename file with value found

Hi, i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file.. ex.. File.txt 1236 43715825601ANDERSSON, 1236 437158256031963040120060901200609010000000 1236 43715825604123 MCCL AVE UPPER 1236 ... (11 Replies)
Discussion started by: dssyadav
11 Replies

6. Programming

curses.h not found , gtk/gtk.h not found

i have downloaded <libncurses5-dev_5.7+20101128-1_i386.deb> and <ndk++-0.0.1alpha4.tar.bz2> which contains the header files curses.h and gtk/gtk.h .. i have also included them using .. #include "/home/ball/Desktop/Sudoku/project/libncurses5-dev_5.7+20101128-1_i386/usr/include/curses.h" ... (2 Replies)
Discussion started by: upvan111
2 Replies

7. Shell Programming and Scripting

Find duplicate based on 'n' fields and mark the duplicate as 'D'

Hi, In a file, I have to mark duplicate records as 'D' and the latest record alone as 'C'. In the below file, I have to identify if duplicate records are there or not based on Man_ID, Man_DT, Ship_ID and I have to mark the record with latest Ship_DT as "C" and other as "D" (I have to create... (7 Replies)
Discussion started by: machomaddy
7 Replies

8. Shell Programming and Scripting

rename files Ax based on strings found in files Bx

Hi, I'm not very experienced in shell scripting and that's probably why I came across the following problem: I do have several hundred pairs of text files (PF00x.spl and PF00x.shd) where the first file (PF00x.spl) needs to be renamed according a string that is included in the second file... (12 Replies)
Discussion started by: inCH
12 Replies

9. Shell Programming and Scripting

how can i check in csh if command found or not found ?

hello all im trying to use in sun Solaris the information received from the top command now i several machines that dont have install the top program so when im running the script im geting error saying after im running this code : set MemoryInfo = `top | grep Memory` if (... (2 Replies)
Discussion started by: umen
2 Replies

10. UNIX for Dummies Questions & Answers

rename using mv ?

Hi all how can can remove the underscore from this number in this series _1234567.abc _1234567.abcd I was trying mv _1234567* 1234567 but did not work ? thanks s (2 Replies)
Discussion started by: simon2000
2 Replies
Login or Register to Ask a Question