Hi.....
I'm using sed command for replace the words in a file
cat >test.txt
My test.txt contains
Mary had a little ham
Mary fried a lot of spam
Jack ate a Spam sandwich
Jill had a lamb spamwich
Marry had a spicy wich
$ sed 's/wich$/mirchi/g' test.txt
output is:
Mary had a little ham
Mary fried a lot of spam
Jack ate a Spam sandmirchi
Jill had a lamb spammirchi
Marry had a spicy mirchi
But I dont want to change combination of wich (i.e., sandwich & spamwich should not change)
plz give me correct command.......if any command other than sed plz send me...I'm waiting for ur reply
$ cat file
Mary had a little ham
Mary fried a lot of spam
Jack ate a Spam sandwich
Jill had a lamb spamwich
wich Marry had a spicy wich
$ ruby -ne 'print $_.gsub(/\bwich\b/,"mirchi") ' file
Mary had a little ham
Mary fried a lot of spam
Jack ate a Spam sandwich
Jill had a lamb spamwich
mirchi Marry had a spicy mirchi
Thanks SHeel and all... who are gave reply to my qstn......
But now Im facing another problem.....
If i want to change the data folder to newdata folder and newdata folder to data folder that same command is not working....
Actually I have path.txt file in that
so if i want to change data to newdata it's ok but after changing the path="f:/sri/project/newdata/doc1
Datapath="f:/sri/project/newdata/file2
sed 's/data/newdata/g' /home/sritest/path.txt
else
sed 's/newdata/data/g' /home/sritest/path.txt
fi
It's not going to else part. in path.txt it again search for data(i.e., in newdata contains data ) there again its changing to newnewdata
that means
im getting following output
Howmany times i run that srcipt that much times its adding newdata into path.txt
but I dont want like this type of output....
I think u all Understood my problem pplz help me out.......
sed 's/ data/ newdata/g' path.txt
Its not working for changing the foldernames.plz giveme as soon as possible reply
thanks a lot... who are giving reply to wich/mirchi for that query....
but I'm facing another problem plz see the before post... i'm not able to run for folders like data folder to newdata folder...plz see the above posted query...plz give me reply that query
If i want to change the data folder to newdata folder and newdata folder to data folder that same command is not working....
Actually I have path.txt file in that
so if i want to change data to newdata it's ok but after changing the path="f:/sri/project/newdata/doc1
Datapath="f:/sri/project/newdata/file2
...
sed 's/data/newdata/g' /home/sritest/path.txt
else
sed 's/newdata/data/g' /home/sritest/path.txtfi
...
It's not going to else part. in path.txt it again search for data (i.e., in newdata contains data ) there again its changing to newnewdata that means im getting following output
Howmany times i run that srcipt that much times its adding newdata into path.txt but I dont want like this type of output.... I think u all Understood my problem pplz help me out.......
sed 's/ data/ newdata/g' path.txt
Its not working for changing the foldernames.plz giveme as soon as possible reply
Note that this command will give you an output where the replacement has been done, BUT the input file /home/sritest/path.txt remain unchanged !
...not sure what you are trying to do with the "else" statement
while read line
do
if [[ $line == *\/data\/* ]]
then
echo `sed -r "s/\/data\//\/newdata\//g" <<<$line`
elif [[ $line == *\/newdata\/* ]]
then
echo `sed -r "s/\/newdata\//\/data\//g" <<<$line`
fi
done <"file1"