Quote:
Originally Posted by
matrixmadhan
Delimiter separating ( / ) search pattern and replace pattern need not be ' / ' always, if there is ' / ' character in the input, you could change the delimiter
Exactly.
The use of "/" to delimit regular expressions is not a rule, just a convention. You could use any other character as long as you are consistent to yourself: "s/x/y/g" is the same as "s:x:y:g", but "s/x:y:g" won't work because once you have used a delimiting character in a regexp you have to stick with it.
Anyways, it is a good idea to escape certain characters anyways, regardless of having a workaround with other delimiting chars or not. Therefor it is advisable to have a separate sed-script modify the input before feeding it to further sed-scripts:
"s/[/\.]/\\&/g"
will "escape" any of the characters "\", "/" and "." by putting a backslash ("\") in front of them. Notice, though, that some backslashes are interpreted by the shell. Play around a bit by trying ("<spc>" is ablank character):
print - "\<spc>" | sed 's/[/\.]/\\&/g'
and modify the string enclosed in the double quotes in the "print -"-statement. Notice, how it changes the behaviour if you remove the space and find out why.
bakunin