Re: sed replace everything between...



On Tue, 16 Aug 2011 06:42:26 -0700, Zak wrote:
i'm trying to search and replace a typical expression in a file such as

\{student "7+9"\} with "7+9"

there are multiple instances in the file of \{student * \} and i want to
search and replace everything found with what the regexp wildcard
represents. I have tried this

s/\(\\{student\) \(*\) \(\\}\)/\2/g

to no avail,
Zak

In file globbing, * stands for 'any string', but in sed and grep
regular expressions, ordinarily * allows previous entity to repeat.
But as it happens, \(*\) will match a single asterisk. For example,
echo 'abc***ghi' | sed 's#\(*\)#hey#g'
gives abcheyheyheyghi

In following, the pattern allows any number of spaces before or
after the inner-match text, and no spaces within that match.

echo 'abc\{student "7+9"\}def\{student "soforth" \}ghi' |
sed 's#\\{student *\([^ ]*\) *\\}#\1#g'

gives: abc"7+9"def"soforth"ghi






--
jiw
.



Relevant Pages

  • Re: Writing to "this", or a general OOP question I guess...
    ... Thanks for the advice on the Singleton Pattern. ... I didn't mean to imply that the Factory Pattern syntax deviated from ... the TItem example was to convey that I want to have multiple instances, ... caching to the end users of the framework. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: printing records containing a pattern
    ... I want to use awk to print the records that contain all the records ... A line can contain multiple instances of xyz. ... fields containg the pattern. ...
    (comp.lang.awk)
  • Re: printing records containing a pattern
    ... I want to use awk to print the records that contain all the records ... A line can contain multiple instances of xyz. ... fields containg the pattern. ...
    (comp.lang.awk)
  • Re: printing records containing a pattern
    ... I want to use awk to print the records that contain all the records ... A line can contain multiple instances of xyz. ... fields containg the pattern. ...
    (comp.lang.awk)
  • Re: printing records containing a pattern
    ... I want to use awk to print the records that contain all the records ... A line can contain multiple instances of xyz. ... fields containg the pattern. ...
    (comp.lang.awk)