Skip to content

Instantly share code, notes, and snippets.

@barryrowlingson
Created January 27, 2015 15:36
Show Gist options
  • Save barryrowlingson/4ec82ea4ad26dcb48b06 to your computer and use it in GitHub Desktop.
Save barryrowlingson/4ec82ea4ad26dcb48b06 to your computer and use it in GitHub Desktop.
sequential file diff
#!/bin/bash
if [ "$#" == "0" ]; then
echo "diff [file1] [file2] ..."
echo " Does diff file1 file2 ; diff file2 file3 ; diff file3 file4 ; etc"
exit 1
fi
first="$1"
shift
while (( "$#" )); do
diff "$first" "$1"
first="$1"
shift
done
@barryrowlingson
Copy link
Author

Needed for comparing monthly update files. Quickly see what changed each month. Use case was some huge NHS prescription chemical CSV files which get published every month, and only one or two lines change most months. Each pair of diff outputs shows the monthly changes.

For my data the first line in each file had the month, so it was obvious which files were being compared, stick an echo in the loop if you need to see explicitly.

I'd like to tweak this so you can pass args through to diff but some other time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment