How can I replace this string with another using sed?
Hey. I searched for answer before asking.
I couldn't seem to find anything that would help. How can I use the search and replace feature using sed? I need to replace some text on about 100 pages. I wanted to find this <!--#exec cgi="/cgi-bin/helper/adoption.pl" --> and replace it with <Script Language="JavaScript" Src="http://www.anysite/helper/one/help.php?help=adoption&r=1"></Script>"; basically I needed to change these tags on all files in a directory including the sub-directories. I tried a few examples and got errors. Your help will be greatly appreciated. Thanks. Dave. |
Code:
sed 's/SEARCH/REPLACE/g' <infile >outfile |
Thanks.
I'll try it tonight when I get home from work. |
Escape characters.... if the sed basic form is
sed s/SEARCHSTRING/REPLACESTRING/g it is worth knowing that you don't have to use / as the delimiting character. You can use any character you please, pretty much. There are lots and lots of / in the expressions you want to search and replace and if you use / you will have to escape all of them. If instead you use ? which appears only once, or z which I think appears no-where in your urls you will have less escaping to do. Best Wishes, Max |
And the '|' character is almost never present in strings to be matched.
|
hey I also have the same problem. i tried what matir and mhoch3 suggested but the problem is i do not want to create new file with different name, i want to keep the same file name and modify it. if i use same name for infile and outfile, it wipes the file clean.what should i do ?
|
perl -pi.bak -e 's/this/that/g' file ... # make a backup
perl -pi -e 's/this/that/g' file ... # don't make a backup |
Quote:
Code:
F=`mktemp` |
All times are GMT -5. The time now is 07:09 AM. |