0
I am using Ubuntu (Precise 12.04) I am trying to write some bash script to see if file is changed via awk replace by using diff command.
I did a test with the following:
#! /bin/bash
diff fileA.htm fileB.htm &> /dev/null
if [ $? -ne 0 ]; then
echo "changed";
else
echo "not changed";
fi
It works, so I am expanding the script like below:
#! /bin/bash
find . \( -name '*.htm' -o -name '*.html' \) \
-exec sh -c \
"awk '/START_TAG/{f=1;print;while (getline < \"REPLACEMENT_FILE.tmp\"){print}}/END_TAG/{f=0}!f' \"{}\" > \"{}.awk\"; diff \"{}\" \"{}.awk\" &> /dev/null; \
if [ $? -ne 0 ]; then\
echo \"{} changed\"; \
else \
echo \"{} not changed\"; \
fi" \;
The awk is working, and the diff command is also working, but I couldn't get the output from diff &> /dev/null and capture in my if statement.
I am assuming when running that within the find -exec statement probably I need to change something there but not sure how to do it.
I don't know much about
awk
, but it seems to me that it would be possible to include a bit of code that would output something if the file was changed. – BenjiWiebe – 2014-07-11T03:30:06.273I guess there are two separate issues here, one is if the script is written correctly for the intended purpose, the other being the question I am posting here. – forestclown – 2014-07-15T08:09:52.393