Created
May 31, 2019 08:26
-
-
Save ElliottLandsborough/2a5ae9a2f819b00dcea765a67f5c236e to your computer and use it in GitHub Desktop.
Combine two text files and compare old vs new, replace if changed
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 | |
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