clear
search_pattern ()
{
read -p " Enter the path where your text file is loscated: " p
read -p "Enter the pattern you want to serch: " pat
pattern=`sed -n "\|$pat|p" $p`
if [ -n "$pattern" ]; then
echo -e "$pattern"
else
echo -e "######### The pattern cannot be found #########"
fi
}
replace_pattern ()
{
read -p " Enter the path where your text file is loscated: " p
read -p "Enter the pattern you want to serch: " pat
read -p "Enter the pattern you want to replace: " reppat
pattern=`sed -n "\|$pat|p" $p`
if [ -f "$p" ]; then
if [ -n "$pattern" ]; then
sed -i "s|$pat|$reppat|" $p
else
echo -e "######### the pattern is not found ############# "
fi
else
echo -e "############ the file is not found #############"
fi
}
read -p " What do you ant to do: [ search or replace ]: " t
case $t in
search ) search_pattern
;;
replace ) replace_pattern
;;
* ) echo -e "please enter search or replace"
--
No comments:
Post a Comment