//Tips tagged diff
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
multiple command output into a single program:
diff -u <(ls -c1 dir_1) <(ls -c1 dir_2)
Will show you a diff of files in the root of dir_1 and dir_2
diff -u <(ls -c1 dir_1) <(ls -c1 dir_2)
Will show you a diff of files in the root of dir_1 and dir_2
You can use diff to see the differences between two files, but it can be useful to see what is the same and more clearly how they differ. This is where comm comes in useful.
comm tells you what information is common to two lists and what information appears uniquely in one or the other.
The first column shows lines only in the first file, the second column lines from the second file and the third column lines from both.
This can be made easier still by adding a bit of perl:
comm tells you what information is common to two lists and what information appears uniquely in one or the other.
$ find . -type f -print -exec cat {} \;
./1.txt
a
b
c
./2.txt
a
c
e
$ comm 1.txt 2.txt
a
b
c
e
The first column shows lines only in the first file, the second column lines from the second file and the third column lines from both.
This can be made easier still by adding a bit of perl:
$ comm 1.txt 2.txt | perl -pe 's/^/1: /g;s/1: \t/2: /g;s/2: \t/A: /g;' | sort 1: b 2: e A: a A: c
vimdiff <(svn cat -r ##ver## foo) foo
will put you in the usual vimdiff output, but comparing between ##ver## and your current version of foo
will put you in the usual vimdiff output, but comparing between ##ver## and your current version of foo
Suppose we have to find the differences between local file "/tmp/localfile" and remote file "/tmp/remotefile" located on remote host 123.4.5.6
This is how can do it:
And using vimdiff:
(of course we would need ssh to work using public key authentication so that we can do remote commands execution without being prompted for passwords).
This is how can do it:
$ ssh user@123.4.5.6 "cat /tmp/remotefile" | diff - /tmp/localfile
And using vimdiff:
$ vimdiff scp://user@123.4.5.6//tmp/remotefile /tmp/localfile
(of course we would need ssh to work using public key authentication so that we can do remote commands execution without being prompted for passwords).
A quick script to compare files from two directories (for example a backup and working directory).
Usage: [script name] directory1 directory2 to check all files
[script name] directory1 directory2 *html to check files of type html.
#!/bin/bash cr='*' if [ -z $3 ]; then cr=$3; fi for f in `find $1/$3 -type f | sed "s|$1/||"` do printf "===!%-76s" "$f!" | tr ' !' '= '; echo diff $1/$f $2/$f | sed -e "s/^</$1: /" -e "s/^>/$2: /" done
Usage: [script name] directory1 directory2 to check all files
[script name] directory1 directory2 *html to check files of type html.

