Skip to content

Instantly share code, notes, and snippets.

@unhammer
Last active December 18, 2015 04:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unhammer/5728652 to your computer and use it in GitHub Desktop.
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
#!/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