Hi.
If you have GNU diff of a certain age, you can do something like:
Code:
#!/usr/bin/env sh
# @(#) s1 Demonstrate diff formatting.
set -o nounset
echo
debug=":"
debug="echo"
## Use local command version for the commands in this demonstration.
echo "(Versions displayed with local utility "version")"
version bash diff
echo
echo " Data files data1 data2:"
cat data1
echo
cat data2
echo
echo " Standard diff output:"
diff data1 data2
echo
echo " Suppress old and unchanged lines, output changed plain:"
diff --changed-group-format="%>" --unchanged-group-format="" data1 data2
exit 0
Producing:
Code:
% ./s1
(Versions displayed with local utility version)
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
diff (GNU diffutils) 2.8.1
Data files data1 data2:
a
b
c
e
a
b
d
e
Standard diff output:
3c3
< c
---
> d
Suppress old and unchanged lines, output changed plain:
d
If you have a diff that does not recognize those options, you can filter the output:
Code:
#!/usr/bin/env sh
# @(#) s2 Demonstrate diff filtering.
set -o nounset
echo
debug=":"
debug="echo"
## Use local command version for the commands in this demonstration.
echo "(Versions displayed with local utility "version")"
version bash diff grep sed
echo
echo " Data files data1 data2:"
cat data1
echo
cat data2
echo
echo " Filtered diff output:"
diff data1 data2 |
grep "^>" |
sed 's/^> //'
exit 0
Which produces:
Code:
% ./s2
(Versions displayed with local utility version)
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
diff (GNU diffutils) 2.8.1
grep (GNU grep) 2.5.1
GNU sed version 4.1.2
Data files data1 data2:
a
b
c
e
a
b
d
e
Filtered diff output:
d
See man diff for details ... cheers, drl
|