How do I compare two values in separate files
I have two files, one like this:
and the second like this:
What i want to do is somehow find out which rows are unique to each file (but ignore the case).
Ideally, the second row in the first file would be changed to this:
abc123 - unique
My files don't have the values above, those are just to show you the idea. Each set of files (I have many I need to compare) has something in the 500 to 600 line/values range.
-Thanks for the help, and I hope my question makes sense
You want the diff command. This is what it was made for.
diff -ui file1 file2
That worked like a charm.
-Thank you very much!
Guess what...I spoke too soon!
The results totally confuse me. Maybe someone can help.
I will post some of the real files so you can see what i mean
What i wanted was the script to tell me that each file already has dv1000 in it, So why is there a - and a + entry for the dv1000 in the results file? Here is what i ran:
diff -ui pavilion1.txt pavilion2.txt > diff.txt
Where did I go wrong?
diff -ui fileone filetwo | grep -v [-+] >outputfile
This will output any shared entries. No output = no shared items.
As for the - and + returned by the command you used, that's how differences are indicated: - means present in file 1 only, + means present in file two only. Neither - nor + means that the item occurs in both files.
In fact, now that I come to think of it, this may be safer:
diff -ui fileone filetwo | grep -v "^[-+].*"
Try using the -y flag in diff. That will print out contents of both files in columns so you can easily compare them and see which lines are different. Might not be very readable if the individual lines are very long though.
There are lots of other flags you can use for different styles of output. Read the man file.
ok, i finally got it working. I had to do
diff -uia --ignore-all-space fileone filetwo
That got it working for some reason. I just randomly tried the ignore all space dash, even thought there are no spaces in either of the files, but it did work.
That's linux commands for you in my experience, sometimes they just don't make sense, but you can still get the job done. Gotta love it. Would have been way more trouble in windows though, so i can't complain.
-Thanks for the help everyone.
Actually, there are spaces in your example files ... eg 'dv1000 cto'
You're right on that one, but my main concern was why did the dv1000 show up with a - and a +. It should have had neither, and appeared only once (indicating that it was in both files).
Diff also checks whether items occupy the same lines in both files. Your items didn't.
|All times are GMT -5. The time now is 03:11 PM.|