in reply to File editing

This problem is tailor-made for the flipflop operator.

perl -i.bak -nwe'(/REx/ .. 0) && print'

Of course, that will print the line that matched the REx. What you really want is hard to tell -- whether you want to start with the line after the REx or whether you want the line with the REx on it, and just starting as soon as the end of the REx matches.

perl -i.bak -nwe'(s/.*REx// .. 0) && print'

That will provide option #2 -- you get everything directly following the REx match, including the text on the same line.

perl -i.bak -nwe'print if $match; /REx/ && $match++'

And this one gives you all of the lines immediately following the line where the REx matched.

All of these examples can also be wrapped in while (<>) { ... } instead of used with the command line switches if necessary.

-dlc

Replies are listed 'Best First'.
RE: Re: File editing
by Jonathan (Curate) on Sep 29, 2000 at 14:20 UTC
    Hey! I like this, never crossed my mind to do a one liner. To be honest I don't care whether the RE line is in or out - it's only a theoretical problem (just a small diversion from writing bloody Sybase SB procs)


    "We are all prompted by the same motives, all deceived by the same fallacies, all animated by hope, obstructed by danger, entangled by desire, and seduced by pleasure." - Samuel Johnson