Last active
December 18, 2015 04:49
-
-
Save unhammer/5728652 to your computer and use it in GitHub Desktop.
call diff on two files, but ignore lines after the length of the shortest one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# -lt 2 ]]; then | |
echo "Usage: $0 file1 file2 [additional options to diff]" | |
exit 1 | |
fi | |
if1=$1 | |
if2=$2 | |
shift 2 | |
trap 'rm -rf "$fifo"' EXIT | |
fifo=$(mktemp -d -t mindiff.XXXXXXXXX) | |
mkfifo "$fifo/1" "$fifo/2" | |
awk -vof1="$fifo/1" -vof2="$fifo/2" ' | |
BEGIN{ f2=ARGV[2];ARGC-- } | |
( (getline line <f2)>0 ) { print > of1; print line > of2 } | |
' "$if1" "$if2" & | |
diff "$@" "$fifo/1" "$fifo/2" | |
rm -rf "$fifo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment