Help with merge and remove duplicates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with merge and remove duplicates
# 1  
Old 04-09-2014
Linux Help with merge and remove duplicates

Hi all,

I need some help to remove duplicates from a file before merging.

I have got 2 files:

file1 has data in format
4300 23456
4301 2357

the 4 byte values on the right hand side is uniq, and are not repeated anywhere in the file

file 2 has data in same format but is not in sorted order

3999 2349
4305 1234
4300 3459

the script i am using is not able to remove duplicate values after spaces, and the output is coming in the following manner:-

3999 2349
4300 233445569
4301 2357
4305 1234

The expected output is:-
3999 2349
4300 234569
4301 2357
4305 1234

The script i am using is:-
Code:
export INPUT1=File1
export REQ=File2
export OUTPUT1=Final_File


sort $INPUT1 $REQ |
           awk     '$1 == SV1              {SV2=SV2  $2;next}
           NR>1 && $1 != SV1                {print SV1, SV2}
                                            {SV1=$1;SV2=$2}
           END                             {print  SV1,SV2}
        ' > $OUTPUT1

# 2  
Old 04-09-2014
I don't see how the 'expected' is different from 'produced'...
Could you provide a better (more representative) set of sample files to explain what you're after.....
# 3  
Old 04-09-2014
For the value 4300

produced value is:
4300 233445569

expected value is:-
4300 234569
# 4  
Old 04-09-2014
You mean you want to change 233445569 to this 234569? and not the records but the repeated values in the fields?
# 5  
Old 04-09-2014
yes....thats correct....
# 6  
Old 04-09-2014
We need to see your script. How is the value from first file 4300 23456 and second file 4300 3459 ending up as 4300 233445569?
# 7  
Old 04-09-2014
The script is given in the 1st post.......................
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