using variable in a regular expression

Chris Robertson chris at mcc.UUCP
Tue May 1 21:44:53 AEST 1990


In article <6400 at star.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
>In article <6358 at star.cs.vu.nl> I wrote:
[Re using a shell variable in a sed expression]
>)...  What would happen if $1 were to contain a slash?
>)I guess sed wouldn't be so pleased with that.

In order to avoid this, make your sed delimiters something uncommon,
like ^A, or my own favourite, ^V.  Or even some fairly ordinary character
not likely to occur in a variable, like ";" -- e.g.:

	sed -e ";$original;$new;" $file > $newfile

Most sed's I've encountered will accept this.

-- 
"Down in the dumps?  I TOLD you you'd     |    Chris Robertson
 need two sets..."                        |  chris at mcc.pyrsyd.oz



More information about the Comp.unix.questions mailing list