[lug] is sed broken?

D. Stimits stimits at idcomm.com
Sat Jul 13 18:44:49 MDT 2002


I'm thinking either sed has a bug (KRUD 7.3), or else it does not
support the full regular expression syntax (probably the latter). I'm
trying to grep for this kind of sample line:
foo="bar"

For regular expression, where bar is unkown, but foo is known, normally
I would think that I could use this:
  foo[=]["].*["]

Or else with some form of escape notation for the quotes, e.g.:
  foo[=]\".*\"

My goal is to replace the quoted part with a different word, e.g., turn:
  foo="abc"
...into:
  foo="xyz"

My sed is similar to:
  cat some.file | sed "s/foo[=]["].*["]/foo="new_value"/" -

The main problem is that I have not found a way to escape the quotes in
the replacement string, it always leaves them out. I have tried \" and
some possible hex/octal escape notations, but did not find it. Can
anyone tell me how to get the replacement text to echo a literal quote
mark? I either get an error, or else it ignores the quotes. Second, is
that the search pattern itself (versus quotes in replacement text) needs
some way to test for the double-quote character. Placing the quote in
square brackets does not do the job as expected from a regular
expression, i.e., ["] fails as a syntax error, so does \". By all
appearances, it seems sed cannot deal with quotes, either as a test
character pattern, or as a replacement value.

D. Stimits, stimits at idcomm.com



More information about the LUG mailing list