Help with merge and remove duplicates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with merge and remove duplicates
# 8  
Old 04-09-2014
Quote:
Originally Posted by roy121
For the value 4300

produced value is:
4300 233445569

expected value is:-
4300 234569
hmmm. I don't quite follow how you get from one to the other given 2 files....
Is there a common field between the 2 files?
Please explain verbally - never mind the script....

Last edited by vgersh99; 04-09-2014 at 05:19 PM..
# 9  
Old 04-09-2014
there are 2 files, both have the value 4300 followed by some codes.
Now we get a request to update the codes.

So the 1st file is the original file which has the value 4300 followed by some codes. The 2nd file also has the value 4300 followed by some more codes which are to be appended.

so when i append the files, i am not able to remove the duplocates after the value 4300 so the result is coming as:-
4300 233445569

Suppose 4300 is a key against which we need to update the values........
# 10  
Old 04-09-2014
please define 'append the field'.
Are concatenating 2 fields in some manner (if so how) and then want to remove sequential digits/letters of the same value?
This is still too vague of a requirement. Please take one record from both files (say 4300) and show how you're 'appending' and how you're 'removing duplicates'.
# 11  
Old 04-09-2014
for gnu awk, try:
Code:
awk '
   NR == FNR { a[$1]=$2 ; b[$1]=$0 ; next}
   {b[$1]= $1 " " $2 a[$1]}
   END {
      for (i in b) {
         fc=b[i]; sub(" .*", "", fc);
         bts=b[i]; sub(".* ", "", bts);
         for (n=1; n<=length(bts); n++) ba[substr(bts,n,1)]=substr(bts,n,1);
         ic=asort(ba,ab) ; bts="";
         for (j=1; j<=ic; j++) {bts=bts ab[j]; delete ba[ab[j]]; delete ab[j]; }
         print fc, bts;
      }
   }
' File1 File2 | sort

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicates

Hi I have a below file structure. 200,1245,E1,1,E1,,7611068,KWH,30, ,,,,,,,, 200,1245,E1,1,E1,,7611070,KWH,30, ,,,,,,,, 300,20140223,0.001,0.001,0.001,0.001,0.001 300,20140224,0.001,0.001,0.001,0.001,0.001 300,20140225,0.001,0.001,0.001,0.001,0.001 300,20140226,0.001,0.001,0.001,0.001,0.001... (1 Reply)
Discussion started by: tejashavele
1 Replies

2. Shell Programming and Scripting

Sort and Remove duplicates

Here is my task : I need to sort two input files and remove duplicates in the output files : Sort by 13 characters from 97 Ascending Sort by 1 characters from 96 Ascending If duplicates are found retain the first value in the file the input files are variable length, convert... (4 Replies)
Discussion started by: ysvsr1
4 Replies

3. Shell Programming and Scripting

Remove top 3 duplicates

hello , I have a requirement with input in below format abc 123 xyz bcd 365 kii abc 987 876 cdf 987 uii abc 456 yuu bcd 654 rrr Expecting Output abc 456 yuu bcd 654 rrr cdf 987 uii (1 Reply)
Discussion started by: Tomlight
1 Replies

4. Shell Programming and Scripting

Remove duplicates

I have a file with the following format: fields seperated by "|" title1|something class|long...content1|keys title2|somhing class|log...content1|kes title1|sothing class|lon...content1|kes title3|shing cls|log...content1|ks I want to remove all duplicates with the same "title field"(the... (3 Replies)
Discussion started by: dtdt
3 Replies

5. UNIX for Dummies Questions & Answers

Remove duplicates from a file

Can u tell me how to remove duplicate records from a file? (11 Replies)
Discussion started by: saga20
11 Replies

6. Shell Programming and Scripting

Merge files without duplicates

Hi all, In a directory of many files, I need to merge only files which do not have identical lines and also the resulatant merge file should not be more than 50000 lines. Basically I need to cover up all text files in that directory and turn them to Merge files.txt with 50000 lines each ... (2 Replies)
Discussion started by: pravfraz
2 Replies

7. Shell Programming and Scripting

Find duplicates in column 1 and merge their lines (awk?)

Hi, I have a file (sorted by sort) with 8 tab delimited columns. The first column contains duplicated fields and I need to merge all these identical lines. My input file: comp100002 aaa bbb ccc ddd eee fff ggg comp100003 aba aba aba aba aba aba aba comp100003 fff fff fff fff fff fff fff... (5 Replies)
Discussion started by: falcox
5 Replies

8. Shell Programming and Scripting

bash - remove duplicates

I need to use a bash script to remove duplicate files from a download list, but I cannot use uniq because the urls are different. I need to go from this: http://***/fae78fe/file1.wmv http://***/39du7si/file1.wmv http://***/d8el2hd/file2.wmv http://***/h893js3/file2.wmv to this: ... (2 Replies)
Discussion started by: locoroco
2 Replies

9. Shell Programming and Scripting

Merge Two Tables with duplicates in first table

Hi.. File 1: 1 aa rep 1 dd rep 1 kk rep 2 bb sad 2 ss sad 3 ee dam File 2 1 apple fruit 2 mango tree 3 lilly flower output: 1 aaple fruit aa,dd,kk rep (7 Replies)
Discussion started by: empyrean
7 Replies

10. Shell Programming and Scripting

Remove duplicates

Hello Experts, I have two files named old and new. Below are my example files. I need to compare and print the records that only exist in my new file. I tried the below awk script, this script works perfectly well if the records have exact match, the issue I have is my old file has got extra... (4 Replies)
Discussion started by: forumthreads
4 Replies
Login or Register to Ask a Question