I have an existing .xml file. I have a shell script which needs to do the following
1) check whether a string is existing in that .xml file or not
2) If that string is not present, then insert a new line in the .xml file with this string at the end
3) save the file
I know I can use tee -a command to append some data at the end of the file. But I need help in writing a shell script command
which can check whether a string is existing and if not create a new line with this string.
grep "pattern" $1 >/dev/null
if [ "$?" -eq "0" ]
then
echo -e "pattern found \n"
exit 0
else
echo "pattern" >> $1
fi
execute ./script.sh file.xml