File comparison based on contents


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File comparison based on contents
# 1  
Old 02-12-2013
Wrench File comparison based on contents

Hi

I have 2 files
1.del
----
Code:
1,2,3,4,5
1,2,3,4,4
1,1,1,1,2

2.del
----
Code:
1,2,3,4,5
1,
1,2,3,4,4
1,1,1,1,2

I need to compare the above two files in unix, as in the output should only tell the difference in contents as I should get only the line
1 ( from 2.del) , rest all lines are present in the both files.
I tried by fetching line by line and comparing in the second file, but its taking a huge time. I have the file size in GB's
Please advise

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by Franklin52; 02-12-2013 at 03:09 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 02-12-2013
if the files are in sorted order please use
Code:
comm

and
Code:
diff

commands . please go through the man page for more details.
This User Gave Thanks to i150371485 For This Post:
# 3  
Old 02-12-2013
Wrench

Thanks for the quick reply.
Can you explain a bit more if the files were in this condition
1.del
----
Code:
1,2,3,4,5
1,2,3,4,4
1,1,1,1,2

2.del
-----
Code:
1,2,3,4,5
1,
1,2,3,4,3
1,2,3,4,4
1,1,1,1,2

and i need only the discrepant rows like
1
1,2,3,4,3 ( The rest all contents are present in some where of the file's). Thanks in advance.

Last edited by Franklin52; 02-13-2013 at 05:09 AM.. Reason: Code tags
# 4  
Old 02-12-2013
PLEASE use code tags as demanded by forum rules!

Why don't you do as i150371485 proposed: read the cited man pages and give it a shot on your sample files? I promise: you will find the discrepant rows.
# 5  
Old 02-12-2013
Wrench

Sorry abt the notations.
I will work on this ..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove or rename based on contents of file

I am trying to use the two files shown below to either remove or rename contents in one of those files. If in file1.txt $5 matches $5 of file2.txt and the value in $1 of file1.txt is not "No Match" then that value is substituted for all values in $5 and $1 of file2.txt. If however in $1 ... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Merging two file based on comparison of first columns

Respected Members. Hello. This is my first post in the forum. I will try to follow all the rules as prescribed by the forum. In case of non-compliance, I request you to kindly give me some more time to understand and abide by them. I am working on two files. I wish to merge the two files... (6 Replies)
Discussion started by: manojmalhotra
6 Replies

3. Shell Programming and Scripting

Merging two file based on comparison of first columns

Respected Members. Hello. This is my first post in the forum. I will try to follow all the rules as prescribed by the forum. In case of non-compliance, I request you to kindly give me some more time to understand and abide by them. I am working on two files. I wish to merge the two files... (1 Reply)
Discussion started by: manojmalhotra
1 Replies

4. UNIX for Dummies Questions & Answers

find lines in another file based on contents in a second file

Hello, I have a file with tab delimited columns like: File1 A 2 C R F 4 D Q C 9 A B ...... I want to grep out the lines in a second file, File2, corresponding to each line in File1 Can I do this: while read a b c d do grep '$a\t$b\t$c\t$d' File2 >>... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

5. UNIX for Dummies Questions & Answers

count values based on contents of another file

Hello, I have two files as shown below: test1 678 679 689 690 710 test2 1 678 654 800 676 791 689 900 I want to get a count of lines from test2 whose columns bound the values in test1 I tried running the code below; however am getting wrong results. (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

6. Shell Programming and Scripting

move contents from one file to another based on line number or content

I want a script that will move everything beyond a certain line number or beyond a certain content word into another file. For example, if file A has this: first line second line third line forth line fifth line sixth line I want to run a script that will move everything beyond the third... (4 Replies)
Discussion started by: robp2175
4 Replies

7. Shell Programming and Scripting

Execution problem with sort the file based on contents

My input file: >ali ASSDDGHFHFHJFJHJDSDGSDGSDGSDGSDGSDGSDGDSGDSGSDGDSGSDGSDGDSGSDGGDSG >zzz ASdASDASDSADSADDSADJKHJDSADKLJADKLSAJDLJLKJLDASDDSADd >abu ASDASDFSAFASFSADFASDASDSADSADSADSADSADSADASDASdSADSADSADA >aaa... (2 Replies)
Discussion started by: patrick87
2 Replies

8. Shell Programming and Scripting

Removing rows from a file based on date comparison

I have a '|' delimited file and want to remove all the records from the file if the date is greater than a year from sysdate. The layout of the file is as below - xxxxxxxxxxxxxx|yyyyyy|zzzzzz|2009-12-27-00:00| 000000000|N xxxxxxxxxxxxxx|yyyyyy|zzzzzz|2010-01-03-00:00| 000000000|N... (4 Replies)
Discussion started by: Max_2503
4 Replies

9. Shell Programming and Scripting

Remove lines based on contents of another file

So, this issue is driving me nuts! I was hoping to get a lending hand here... I have 2 files: file1.txt contains: this is example1 this is example2 this is example3 this is example4 this is example5 file2.txt contains: example3 example5 Basically, I need a script or command to... (4 Replies)
Discussion started by: bashshadow1979
4 Replies

10. Shell Programming and Scripting

sh script that reads/writes based upon contents of a file

Hi everyone, Ive got a quick question about the feasibility and any suggestions for a shell script. I can use sh or ksh, doesnt matter. Basically, Ive got an output file from a db2 command that looks like so: SCHEMA NAME CARD LEAF ELEAF LVLS ISIZE NDEL KEYS F4 F5 ... (3 Replies)
Discussion started by: rdudejr
3 Replies
Login or Register to Ask a Question