I\'m trying to write a simple Bash script. I have a simple \"template\" variable:
template = \"my*appserver\"
I then have a function (
Yeah, either 'sed' as the others have said, or start with your template in 2 separate variables and construct on the fly. e.g.
templateprefix="my"
templatesuffix="appserver"
server=get_env
template=${templateprefix}${server}${templatesuffix}
Here's a bash script that wraps this up
$ search_and_replace.sh "test me out" "test me" ez
ez out
#!/bin/bash
function show_help()
{
echo ""
echo "usage: SUBJECT SEARCH_FOR REPLACE_WITH"
echo ""
echo "e.g. "
echo ""
echo "test t a => aesa"
echo "'test me out' 'test me' ez => ez out"
echo ""
exit
}
if [ "$1" == "help" ]
then
show_help
exit
fi
if [ -z "$3" ]
then
show_help
exit
fi
SUBJECT=$1
SEARCH_FOR=$2
REPLACE_WITH=$3
echo "$SUBJECT" | sed -e "s/$SEARCH_FOR/$REPLACE_WITH/g"