Monday, September 25, 2023

1) Search and replace text script  -- script name replace.sh


#!/bin/bash
# script to search and replace text and take backup file
if [ $# != 3 ] ; then
echo "Input error : syntax replace < search path> <search string> < replace string>
exit 1
elif [ ! -e $1 ] ; then
echo "Given Path $1 doesnt exist"
exit 1
else
find $1 -type f -iname *.log -exec sed -i-$(date +%d-%m-%y) "s/$2/$3/g" {} \;
exit 0
fi

2) Execution outcome