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):
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
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