bill lam <[EMAIL PROTECTED]> asked:
> Suppose I want to change 2 lines to 3 line in files as follow 
> using perl -p -i -e command aa bb
> 
> aa
> cc
> bb
> 
> this doesn't work
> perl -p -i -e "s/aa\nbb/aa\ncc\nbb/g;" foo.txt

That won't work since you ever only see a single line of input.

Since you don't insert new data into the first line of the match,
you could keep track of the previous line in $p and then use
two matches against $p and $_ to determine if you have the line
pair that you want to match.

perl -i -ple '$_ = "cc\n$_" if $p =~ m/aa/ && m/bb/; $p=$_'

HTH,
Thomas

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to