Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

UNIX file comparision

Posted on 2005-04-22
5
Medium Priority
?
353 Views
Last Modified: 2013-12-26
I want some help comparing 2 files on UNIX.
Would it be possible to compare file1 vs file and write all records from file1.txt that are not in file to file3 ?

Is there any command to do this?

Eg:
File1:

111111
222222
333334
444444

File 2:

333333
444444

file 3-Output file:

111111
222222
333334

Thanks
Issac
0
Comment
Question by:issacmj
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
nikkilocke earned 500 total points
ID: 13842752
Hi issacmj,

fgrep -v -f file2 file1 >file2

This will output file3 containing all lines from file1 that are not in file2.

Hope this helps,

Nikki
0
 
LVL 1

Author Comment

by:issacmj
ID: 13843841
It worked!!!!

Thanks
Issac
0
 
LVL 1

Author Comment

by:issacmj
ID: 13844030
I tried running this command on a big file. gave me "grep: memory exhausted" error. Is there any other command which will work with big files?

Thanks
Issac


0
 
LVL 1

Author Comment

by:issacmj
ID: 13844946
I was told that i can use "diff" to achieve this. But i have to sort the files first. Any idea how? or some other method?
0
 
LVL 2

Expert Comment

by:nikkilocke
ID: 13845129
sort <file1 >file1.sorted
sort <file2 >file2.sorted
diff file1.sorted file2.sorted

You will probably have to mess further with the output of diff to get just the output you want. Try the different diff options to see which one is easiest to munge into the output you want.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question