How to combine 2 files and output the unique & difference?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to combine 2 files and output the unique & difference?
# 1  
Old 07-30-2011
How to combine 2 files and output the unique & difference?

Hi Guys,

I have two input files and I want to combine them and get the unique values and differences and put them into one file. See below desired output file.


Inputfile1:
Code:
1111111
2222222
3333333
7860068
7860069
7860071
7860072


Inputfile2:
Code:
4444444
5555555
6666666
7860068
7860069
7860071
7860072



DESIRED OUTPUT FILE:
Code:
1111111
2222222
3333333
4444444
5555555
6666666
7860068
7860069
7860071
7860072


Thanks on advance!


Br,
pinpe
# 2  
Old 07-30-2011
Use "sort" with the "-u" (unique) option, quite straightforward:

Code:
cat /path/to/file1 /path/to/file2 | sort -u > /path/to/result

I hope this helps.

bakunin
# 3  
Old 07-31-2011
Code:
sort -u file[1,2] > file3

Smilie
This User Gave Thanks to danmero For This Post:
# 4  
Old 07-31-2011
Where is Corona\d+ ? He surely would give the link to "Useless use of cat". Smilie
# 5  
Old 07-31-2011
Quote:
Originally Posted by danmero
Code:
sort -u file[1,2] > file3

Smilie
This is more efficient command than using cat. Thanks dude! Smilie Smilie

Br,
pinpe
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difference output of files

Need help on below req Compare two files and send difference of file to other file File2 is static which never changes ex: File1 A.txt B.ttx C.txt E.txt File2 A.txt (6 Replies)
Discussion started by: satish1222
6 Replies

2. Shell Programming and Scripting

Combine splitted low & high byte files into one file

Hi all, i have a binary file splitted into 2 chunks, first part with all high bytes and the second part with all low bytes. I need to combine the two chunks into one binary file like (eg. exactly the reverse of the splitting method solved in the thread # 130940) Hi bytes file content:... (7 Replies)
Discussion started by: mzs
7 Replies

3. 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

4. Shell Programming and Scripting

Compare multiple files, identify common records and combine unique values into one file

Good morning all, I have a problem that is one step beyond a standard awk compare. I would like to compare three files which have several thousand records against a fourth file. All of them have a value in each row that is identical, and one value in each of those rows which may be duplicated... (1 Reply)
Discussion started by: nashton
1 Replies

5. Shell Programming and Scripting

Finding a text in files & replacing it with unique strings

Hallo Everyone. I have to admit I'm shell scripting illiterate . I need to find certain strings in several text files and replace each of the string by unique & corresponding text. I prepared a csv file with 3 columns: <filename>;<old_pattern>;<new_pattern> ... (5 Replies)
Discussion started by: gordom
5 Replies

6. Shell Programming and Scripting

grep with date & unique output

alert.log has the entries with ORA-XXXX, .... Mon Sep 24 15:08:09 2012 WARNING: inbound connection timed out (ORA-3136) Mon Sep 24 15:08:09 2012 WARNING: inbound connection timed out (ORA-3136) Mon Sep 24 15:08:09 2012 WARNING: inbound connection timed out (ORA-3136) Mon Sep 24 15:15:01... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

7. Shell Programming and Scripting

Difference of two data files & writing to an outfile.

Hi Everyone, I have two files i.e. one file2 contains today's data and the other file1 contains Yesterday's data. The data in the files contains 226 columns and the data for the coulums separated by a Pipe "|" delimiter. Now, I have 4 Primary keys (coulumns) by which I have to compare file2 and... (10 Replies)
Discussion started by: filter
10 Replies

8. Shell Programming and Scripting

get part of file with unique & non-unique string

I have an archive file that holds a batch of statements. I would like to be able to extract a certain statement based on the unique customer # (ie. 123456). The end for each statement is noted by "ENDSTM". I can find the line number for the beginning of the statement section with sed. ... (5 Replies)
Discussion started by: andrewsc
5 Replies

9. UNIX for Dummies Questions & Answers

output difference in two files

Hi, Please help me, I have two files. I need to output the difference of contents of each file in another file. For example, I need to know the content of the file1 that does not exist on file2 and vice versa. Please take note that the size of the files are large. How can I do it using unix... (4 Replies)
Discussion started by: ayhanne
4 Replies

10. UNIX for Dummies Questions & Answers

How to output the difference of two files?

Hi, I had two data file (File1, File2), each one just have one column, but two file were very big. File2 is smaller, all its data included in File1. I want to ouput the result which don't have any data in File2. Could any one give me a help on how to do that? Thanks in advance! Yun ... (4 Replies)
Discussion started by: yxiao
4 Replies
Login or Register to Ask a Question