The following shell script, when given an argument of the form file1.x
, generates a series of diffs. It increments the last series of digits in the file name (so you can start at file0.x
or file42.x
) and goes on until it finds a missing number.
#!/bin/sh
current=$1
suffix=${1##*[0-9]}; digits=${1%"$suffix"}
digits=${digits##*[!0-9]}; prefix=${1%"$digits$suffix"}
while
leading_zeros=${digits%%[1-9]*}; digits=${digits#$leading_zeros}
case $digits in
*[!9]*) digits=$leading_zeros$((digits+1));;
*) digits=${leading_zeros%0}$((digits+1));;
esac
next=$prefix$digits$suffix
[ -e "$next" ]
do
diff -u -- "$current" "$next" >"$next.diff"
current=$next
done
Rather than generate a bunch of diffs, it may be more convenient to enter the versions into version control, and use nice VC tools to explore the successive revisions. To do that, initialize version control (e.g. git init
), add the initial file (e.g. cp file1.x file.x && git add file.x && git commit -m "version 1"
), and instead of generating diffs (the diff
line in the script above) commit the successive versions (e.g. cp -- "$next" "$prefix$suffix" && git commit -m "Version $digits" -- "$prefix$suffix"
).
diff
all the possible combinations, or just each file with the next in line... could you please elaborate on that?