file comparing script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file comparing script
# 1  
Old 01-06-2011
file comparing script

Hi Guys,

I need a help in putting a script which compares 2 files which has some names on it. I would like to compare both the files and put the common ones in another file, could anyone help me how to do that?

Also I want to do the same for 3 files also? I am a beginner in the scripting and any help would be greatly appreciated.

Regards,

RR
# 2  
Old 01-06-2011
Look at man comm
comm
This User Gave Thanks to anurag.singh For This Post:
# 3  
Old 01-06-2011
Thanks So much. It just works as what i was expecting for 2 files. Thanks for letting me know this command.

But I am unable to use 3 files. is there anyway I can compare 3 files ?

ex :

File 1
******
a
b
c
d

File 2
*******
a
c
d

File 3
******
a
b
c
d


Output :
********
a
c
d
# 4  
Old 01-06-2011
There is a EXAMPLES section in man page of comm.
That has exactly what you want. Get common data for 3 files.
Idea is, pipe the output of 2 files to the 3rd file.
Pls try. If you get further problem, will give the command.
This User Gave Thanks to anurag.singh For This Post:
# 5  
Old 01-06-2011
Code:
grep -f <(grep -f file1 file2 ) file3

This User Gave Thanks to rdcwayx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for Comparing directories and file from a text file

Hello all, I need to write a script which has following requirement: Need to read the filenames from text file and then search for the above read files in the required directory and if match found backup them in a backup folder. And also need to compare and verify whether the files in the... (7 Replies)
Discussion started by: saurau
7 Replies

2. UNIX for Dummies Questions & Answers

Comparing to specific line in file bash script

Hi, I have a value stored in x and I need to compare it to the numbers in every other line of a file. The file contains alternating lines of numbers and letters: aaaa1111 AAAAAAAA bbbb2222 BBBBBBBB cccc3333 CCCCCCCC I need to compare x to the numbers in every other line without the... (2 Replies)
Discussion started by: ShiGua
2 Replies

3. Shell Programming and Scripting

Comparing two csv file fields using awk script

Hi All, I want to remove the rows from File1.csv by comparing the columns/fields in the File2.csv. I only need the records whose first column is same and the second column is different for the same record in both files.Here is an example on what I need. File1.csv: RAJAK|ACTIVE|1... (2 Replies)
Discussion started by: rajak.net
2 Replies

4. Shell Programming and Scripting

Remove duplicate lines from first file comparing second file

Hi, I have two files with below data:: file1:- 123|aaa|ppp 445|fff|yyy 999|ttt|jjj 555|hhh|hhh file2:- 445|fff|yyy 555|hhh|hhh The records present in file1, not present in file 2 should be writtent to the out put file. output:- 123|aaa|ppp 999|ttt|jjj Is there any one line... (3 Replies)
Discussion started by: gani_85
3 Replies

5. Shell Programming and Scripting

Comparing rows in same file and writing the result in new file

Help needed... Can you tell me how to compare the last two couple entries in a file and print their result in new file..:confused: I have one file Check1.txt \abc1 12345 \abc2 12327 \abc1 12345 \abc2 12330 I want to compare the entries in Check1 and write to... (1 Reply)
Discussion started by: kichu
1 Replies

6. Shell Programming and Scripting

Comparing 2 file use c shell script

Hi all, I got 2 file : file1: file2: output: But , must write out in C shell.Anybody can help solve? (6 Replies)
Discussion started by: proghack
6 Replies

7. Shell Programming and Scripting

Need help in comparing a file with log file: perl code

Dear Members, I need a perl code: 1. Which will open first file with two columns separated by tab: 37 Distribution and seasonal variation of trace metals 85 Seasonal variability of the mixed layer in the central Bay 99 Dynamics of transparent exopolymeric particles (TEP) 103 Bacterial... (0 Replies)
Discussion started by: srsahu75
0 Replies

8. Shell Programming and Scripting

Awk script / comparing two files

Goal: To combine the data from two files into one file. File1 = 11 fields, the first field is the unique key File2 = 2 fields, the first field is the unique key What I want to do is match File2:column1 with File1:column1 and if it matches, to add the data from File2:column2 to the matching... (2 Replies)
Discussion started by: jmcgranahan
2 Replies

9. Shell Programming and Scripting

script for comparing the times.

Hi, My below output file looks like this. Backup status at Tue Jul 7 03:30:07 EDT 2009 CMLP Job Name Last Start Last End ST Run Pri/Xit ____________________________ ____________________ ____________________ __ _______ ___ tnx415uu 07/06/2009 22:01:41 ----- RU 5547800/1 tnp415uu 07/06/2009... (2 Replies)
Discussion started by: intiraju
2 Replies

10. Shell Programming and Scripting

shell script comparing files in a file

There is a text file that contains the data in the following format: COLUMN1 COLUMN2 ABC 1 ABC 2 ABC 3 DEF 4 DEF 5 XYZ 7 We have to create a second text file... (4 Replies)
Discussion started by: raina_nalin
4 Replies
Login or Register to Ask a Question