Re: sed replace everything between...
- From: James Waldby <not@xxxxxxxxxxxxx>
- Date: Tue, 16 Aug 2011 15:16:41 +0000 (UTC)
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
.
- References:
- sed replace everything between...
- From: Zak
- sed replace everything between...
- Prev by Date: Re: a simple question
- Next by Date: Re: a simple question
- Previous by thread: Re: sed replace everything between...
- Next by thread: Re: sed replace everything between...
- Index(es):
Relevant Pages
|