problem with sed n variable in shell script
hii ..
i have a problem in using sed .. awk is very complicated for me .. my task is a simple stuff .. i have to create a script in which i have to take three input
1>filename
2>first word
3> second word
in this script i have to just replace every instance of first word by second word in file supplied
here is my silly script
#!/bin/bash
ls $1 > /dev/null
if [ $? -eq 1 ]
then
echo file not found
fi
cat $1 | sed 's/$2/$3/g'
when i supply constant string instead of variable .. its doing my work .. like if i give
instead of $2 and $3 like
sed 's/dipen/ass/g'
its replacing dipen by ass .. in the file ..
so again i m stuck by not able to expand my variable ..
i tried everything .. somethings i tried were
sed 's/`echo $2`/`echo $2`/g'
sed 's/${!1}/${!2}/g'
i have tried using escape sequence almost everywhere ..
thnks in advance
|