How to search and replace
dan.track at gmail.com
Fri Feb 3 10:33:15 UTC 2006
On 2/3/06, Paul Howarth <paul at city-fan.org> wrote:
> Dan Track wrote:
> > Just wondering if you could exaplin something to me:
> > 1) What does the following mean in plain english ^\(Target\[[^]]*\].
> > I'm getting confused by the number of "[" brackets. To be specific I
> > can't see how this part \[[^]]*\] is working. The \[ indicates the
> > match to the "[" string but what I read from [^]] here is that I want
> > the regular expression to match any of these ^] charaters. But there
> > isn't a ^ charater or a ].
> I'll take it element by element.
> ^ = Anchor the expression to the start of a line,
> \( ... \) = sed "remembers" whatever matches the expression between \(
> and \) and will use that text in the replacement part of the
> search-and-replace - a "\1" means the first "remembered" text, a "\2"
> means the second "remembered" text etc.
> Terget = boilerplate text to be matched
> \[ = match the literal character "["
> [^]] = match any character except "]"
> > 2) What does $!N mean.
> I pulled this from the sed FAQ, which explains it better than I could:
> Note that the 'N' followed by the 'P;D;' commands forms a "sliding
> window" technique. A window of N lines is formed. If the multi-line
> pattern matches, the block is handled. If not, the top line is printed
> and then deleted from the pattern space, and we try to match at the
> next line."
> $!N literally means "if we're not at the end of the file, read the next
> line into the pattern space"
Thanks very much for your time and help. I've learnt a lot from this.
More information about the users