Skip to content

Instantly share code, notes, and snippets.

@ElliottLandsborough
Created May 31, 2019 08:26
Show Gist options
  • Save ElliottLandsborough/2a5ae9a2f819b00dcea765a67f5c236e to your computer and use it in GitHub Desktop.
Save ElliottLandsborough/2a5ae9a2f819b00dcea765a67f5c236e to your computer and use it in GitHub Desktop.
Combine two text files and compare old vs new, replace if changed
#!/bin/bash
FILE="/home/user/replaceable.txt";
TMPFILE="/tmp/file.txt";
FILE1="/home/user/file1";
FILE2="/home/user/file2";
# generate new key in temp location
cat $FILE1 $FILE2 > $TMPFILE;
# compare the files
if /usr/bin/cmp -s "$TMPFILE" "$FILE" ; then
/bin/echo 'Files are equal, doing nothing.'
else
/bin/echo 'Files changed.'
/bin/rm $FILE;
/bin/cp $TMPFILE $FILE;
fi
/bin/rm $TMPFILE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment