grep script/syntax
Hi all,
I was originally working with this script that would compare two text files. This script compares the files and lists the matching line if there is a match, or the matching line and the word 'NOT' if it doesn't match. Code:
exec 3< /usr/local/photodir-.txt Code:
exec 3< /usr/local/photodir-.txt Code:
exec 3< /usr/local/photodir-.txt Thanks, Carrie |
diff - find differences between two files
Check man diff. |
Although diff does a lot more than just what you want to do, you should be able to adapt to it.
|
Good, but missing something
Well, I have found diff to work much faster, but as far as I've read, the closest I can come to what I want is by displaying all of the results, not just the ones that don't match:
Code:
diff -u /usr/local/photodir-.txt /tmp/mlsnos.txt Is there a way to use diff to display just the lines that do not match? Carrie |
How about
diff -u /usr/local/photodir-.txt /tmp/mlsnos.txt cat /tmp/mlsnos.txt |grep - > /tmp/notinmlsnos.txt - for the preceding minus sign Hope it helps, Pete |
Check out the "comm" command. By default it compares two files and it's output is in three columns: (1) lines only in file 1, (2) lines only in file 2, and (3) lines in both files.
You can give comm some commandline parameters to suppress one or more columns of the default output. e.g., "comm -1 file1 file2" will suppress column one (lines unique to file 1) e.g., "comm -12 file1 file2" suppresses columns one and two, and lists ONLY lines that are common to both files. Run "man comm" to see invokation details. |
Quote:
or diff -u0 <file1> <file2> or diff -c0 <file1> <file2> |
All times are GMT -5. The time now is 12:16 PM. |