|
Home > Archive > Unix Programming > June 2006 > how to use "sed" to replace old directory to new directory in a file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to use "sed" to replace old directory to new directory in a file
|
|
|
| All
please guid me....
i want to know how to replace the old directory to new directory in a
file..
example: let us consider the below line
open (LOG,">>/user/xxxx/yyyy/zzzz/aaaa/bbbb/.cccc") || die;
to
open (LOG,">>/wwww/qqqqq/pppp/rrrrr/ssss/tttt/.lllll") || die;
like this i want to replace many lines in which each line has different
directories to new different directory
i tried with
oldpath=/user/xxxx/yyyy/zzzz/aaaa/bbbb/.cccc
newpath=/wwww/qqqqq/pppp/rrrrr/ssss/tttt/.lllll
cat -n filename | grep 61 | sed "s/$oldpath/$newpath/" filename
am getting error
(where 61 is the line no. where i have to do changes...)
help me pls...
waiting for reply
thanx n advance
sk
| |
| David Bolt 2006-06-29, 7:37 am |
| On Thu, 29 Jun 2006, sk <sangeetha.kolandasamy@gmail.com> wrote:-
>i tried with
>oldpath=/user/xxxx/yyyy/zzzz/aaaa/bbbb/.cccc
>newpath=/wwww/qqqqq/pppp/rrrrr/ssss/tttt/.lllll
>cat -n filename | grep 61 | sed "s/$oldpath/$newpath/" filename
>am getting error
>(where 61 is the line no. where i have to do changes...)
Try replacing the
sed "s/$oldpath/$newpath/"
with
sed "s#$oldpath#$newpath#"
Your error is probably because the s/$oldpath/$newpath/ is expanding to
s//user/xxxx/yyyy/zzzz/aaaa/bbbb/.cccc//wwww/qqqqq/pppp/rrrrr/ssss/tttt/.
lllll/
changing the three /'s to some other character, # in my example, means
the / can appear as part of the search/replace string without having to
be escaped.
Regards,
David Bolt
--
Member of Team Acorn checking nodes at 50 Mnodes/s: http://www.distributed.net/
AMD1800 1Gb WinXP/SUSE 9.3 | AMD2400 256Mb SuSE 9.0 | A3010 4Mb RISCOS 3.11
AMD2400(32) 768Mb SUSE 10.0 | Falcon 14Mb TOS 4.02 | A4000 4Mb RISCOS 3.11
AMD2600(64) 512Mb SUSE 10.0 | | RPC600 129Mb RISCOS 3.6
|
|
|
|
|