compare 2 files, output dups to file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers compare 2 files, output dups to file
# 1  
Old 07-14-2004
compare 2 files, output dups to file

I have two files that I want to compare and output a new file that will contain the duplicates. I have tried comm -12 and it doesn't work? Any help will be helpful.

Thanks,
Barbara
# 2  
Old 07-14-2004
comm -12 should do what you want, provided you redirect the output to a new file, and (this is the biggy) ensuring that both input files are SORTED.

Code:
sort file1.txt > file1_sorted.txt
sort file2.txt > file2_sorted.txt

comm -12 file1_sorted.txt file2_sorted.txt > file3_dups.txt

more file3_dups.txt

Peace
ZB
# 3  
Old 07-15-2004
Thanks - sorting is the key obviously!

Much appreciated.....
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 files the send output to a file

Hallo Friends, I would like to compare two files, then write the difference between the two into output file then find a pattern then search for that pattern. -bash-3.2$ cat BS_Orig_20141112.csv|head -20 BW0159574451211141638275086@196.35.130.5 BW02043750712111491637691@196.35.130.5... (2 Replies)
Discussion started by: kekanap
2 Replies

2. UNIX for Dummies Questions & Answers

To compare two files,Output into a new file

Hi Please help me to compare two files and output into a new file file1.txt 15114933 |4001 15291649 |933502 15764675 |4316 15764678 |4316 15761974 |282501 15673104 |933505 15673577 |933505 15673098 |933505 15673096 |933505 15673092 |933505 15760705 ... (13 Replies)
Discussion started by: Ankita Talukdar
13 Replies

3. UNIX for Dummies Questions & Answers

Compare two files and output to new file

Hi, Please help How to compare two files- Any mismatches 2nd and 3rd column's values corresponding to 1st column. file1 15294024|Not Allowed|null 15291398|Not Allowed|null 15303292|Dropship (standard)|N 15303291|Dropship (standard)|N 15275561|Store Only|Y 15275560|Store Only|Y... (2 Replies)
Discussion started by: Ankita Talukdar
2 Replies

4. Shell Programming and Scripting

Compare columns of multiple files and print those unique string from File1 in an output file.

Hi, I have multiple files that each contain one column of strings: File1: 123abc 456def 789ghi File2: 123abc 456def 891jkl File3: 234mno 123abc 456def In total I have 25 of these type of file. (5 Replies)
Discussion started by: owwow14
5 Replies

5. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

6. Shell Programming and Scripting

Compare two files and output in another file

I have two files ' 1st one ALIC-000352-B ALIC-000916-O DDS-STNGD FDH-PPO1-001 PFG-30601-001 2nd one 'ALIC-000352-B' 'ALIC-000916-O' 'DDS-STNGD' 'FDH-PPO1-001' (4 Replies)
Discussion started by: Pratik4891
4 Replies

7. UNIX for Advanced & Expert Users

Shell Script to compare xml files and print output to a file

All, PLease can you help me with a shell script which can compare two xml files and print the difference to a output file. I have attached one such file for you reference. <Group> <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

8. Shell Programming and Scripting

awk to compare flat files and print output to another file

Hello, I am strugling from quite a some time to compare flat files with over 1 million records could anyone please help me. I want to compare two pipe delimited flat files, file1 with file2 and output the unmatched rows from file2 in file3 Sample File1: ... (9 Replies)
Discussion started by: suhaeb
9 Replies

9. Shell Programming and Scripting

Compare two files and output diff to third file

I have made several attempts to read two files of ip addresses and eliminate records from file1 that are in file2. My latest attempt follows. Everything works except my file3 is exactly the same as file1 and it should not be. # !/usr/bin/bash # # NoInterfaces # Utility will create a file... (8 Replies)
Discussion started by: altamaha
8 Replies

10. Shell Programming and Scripting

compare two col from 2 files, and output uniq from file 1

Hi, I can't find how to achive such thing, please help. I have try with uniq and comm but those command can't compare columns just whole lines, I think awk will be the best but awk is magic for me as of now. file a a1~a2~a3~a4~a6~a7~a8 file b b1~b2~b3~b4~b6~b7~b8 output 1: compare... (2 Replies)
Discussion started by: pp56825
2 Replies
Login or Register to Ask a Question