How to compare several files and create a new one


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to compare several files and create a new one
# 1  
Old 07-17-2006
How to compare several files and create a new one

Hello,
I have a few files with simple data on them. All of the files may contain the same and different data. I need to create a new file that contains data that is on all files at the same time. Let say if word "ffffffff" is on all files it must be in the new file. If word "kkkkkkk" is not on all files then it must not be on the new file. Can anyone give me a solution at least for the case when there are only two files.

Thank you in advance.
# 2  
Old 07-18-2006
For two files, you can use the comm command. Use the -12 switch to supress the output of lines present in only one of the two files. You will end up with the output that is common to the two files. Like so:
Code:
# cat test1
aaa
bbb
ccc
# cat test2
aaa
bbb
ddd
# comm -12 test1 test2
aaa
bbb

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare 2 files and create a result file with unmatched lines from first file.?

HI, I have 2 text files. file1 and file2. file1.txt (There are no duplicates in this file) 1234 3232 4343 3435 6564 6767 1213 file2.txt 1234,wq,wewe,qwqw 1234,as,dfdf,dfdf 4343,asas,sdds,dsds 6767,asas,fdfd,fdffd I need to search each number in file1.txt in file2.txt's 1st... (6 Replies)
Discussion started by: Little
6 Replies

2. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

3. Shell Programming and Scripting

How to create a script to compare 2 files?

I have two files File1 and File2 will contains same number of fields. The rows in File1 can be found anywhere in File2. If any rows from File1 doesn't match to File2 then write those records to a File1 log file. If any rows from File2 doesn't match to File1 then write those records to a File2... (6 Replies)
Discussion started by: ranjanp
6 Replies

4. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

5. Shell Programming and Scripting

Compare 2 folders to find several missing files among huge amounts of files.

Hi, all: I've got two folders, say, "folder1" and "folder2". Under each, there are thousands of files. It's quite obvious that there are some files missing in each. I just would like to find them. I believe this can be done by "diff" command. However, if I change the above question a... (1 Reply)
Discussion started by: jiapei100
1 Replies

6. Shell Programming and Scripting

How to compare 2 files & get only few columns based on a condition related to both files?

Hiiiii friends I have 2 files which contains huge data & few lines of it are as shown below File1: b.dat(which has 21 columns) SSR 1976 8 12 13 10 44.00 39.0700 70.7800 7.0 0 0.00 0 2.78 0.00 0.00 0 0.00 2.78 0 NULL ISC 1976 8 12 22 32 37.39 36.2942 70.7338... (6 Replies)
Discussion started by: reva
6 Replies

7. Shell Programming and Scripting

compare files in two directories and output changed files to third directory

I have searched about 30 threads, a load of Google pages and cannot find what I am looking for. I have some of the parts but not the whole. I cannot seem to get the puzzle fit together. I have three folders, two of which contain different versions of multiple files, dist/file1.php dist/file2.php... (4 Replies)
Discussion started by: bkeep
4 Replies

8. Shell Programming and Scripting

Compare two csv files by two colums and create third file combining data from them.

I've got two large csv text table files with different number of columns each. I have to compare them based on first two columns and create resulting file that would in case of matched first two columns include all values from first one and all values (except first two colums) from second one. I... (5 Replies)
Discussion started by: agb2008
5 Replies

9. UNIX for Dummies Questions & Answers

Compare unique ID's to Create and Delete Times

I have thousands of lines a day of data I would like to sort out. Every sessions has the 3 lines below. I want to figure out each sessions length from Creation to Deletion. Every one has a unique session ID logevent3:<190>Nov 20 08:41:06 000423df255c: 6|4096|RC|CAC: Created CAC session ID... (2 Replies)
Discussion started by: bpfoster7
2 Replies

10. Shell Programming and Scripting

compare files and create new with awk

hi everybody: Anybody know how I can compare two files where the pattern would be the three firsts columns of each file to create another one. This is, I have two file: file1 is like: 20030601 14 05 498.985 0.436532 20030601 14 10 499.531 0.260819 20030601 14 15 499.427 0.508597... (7 Replies)
Discussion started by: tonet
7 Replies
Login or Register to Ask a Question