Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

special characters and sed

Status
Not open for further replies.

cmeyers

Programmer
Jul 6, 2001
24
US
Hi,

I've got an oddball situation.

I'm trying to expand a shell variable string in a sed statement. The string contains a special character. In this case the character is a forward slash (/). I believe other special characters will cause a similar problem - like parentheses, brackets, etc.

Here's the problem code (I work in ksh):

Code:
STRVAR=lbm/sec
sed "s/$STRVAR/substitution text/g" /somepath/somefile

Actually the string is assigned to STRVAR by parsing a text file. So, I obviously don't have an opportunity to "escape" the forward slash. The shell expands $STRVAR and sed gets very confused - something like "garbled command".

I was hoping for some regular expression blackmagic solution with a really cool metacharacter sequence that will put this one to bed. Or maybe there is some subtle ksh variable stuff that I could do.

Any ideas? I'm at a loss.

CraigMan
 
BTW - there is no CR between "substitution" and "text". I'm not sure how this line was fractured.
 
I solved my own problem.

I used an infrequently used character like this:

Code:
sed "s~$STRVAR~substitution text~g" /path/file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top