Reputation: 942
I'm trying to get diff to output only the name of the modified files. I tried to use the -q option but it's still giving me too much output :
What i get now is this :
files path/to/file1/file1 and path/to/file2/file2 are different
And i would like this :
path/to/file1/file1
Any ideas on how to do this ?
Upvotes: 2
Views: 4669
Reputation: 125
Another option is to use cmp --silent
instead of diff -q
. This sends nothing to stdout, so you only need to deal with the exit status.
For example:
file1=path/to/file1/file1; cmp --silent $file1 path/to/file2/file2 || echo $file1
The exit status of cmp is the same as diff (0 if inputs are the same and 1 if different).
Upvotes: 1
Reputation: 6246
Similar to Wes's answer:
echo "files path/to/file1/file1 and path/to/file2/file2 are different" | sed -e "s/^files //" -e "s/ and .*$//"
.
//output
path/to/file1/file1
Upvotes: 1
Reputation: 96266
Use the exit status of diff:
if ! diff -q file1 file2 >/dev/null; then echo file1; fi
Upvotes: 3
Reputation: 22262
You can always pipe it to something else, such as:
# diff ... | sed 's/^files //;s/ and .*//;'
However, note that if you have a file with a literal " and " in it, then the above will cause a problem. Generally I encourage people not to use spaces in file names anyway. Yes you can do it, but yes it still causes problems.
Upvotes: 1