CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Kdawg01] Copying a file and modifying line order output: Edit Log



Chris Charley
User

Mar 23, 2013, 11:06 AM


Views: 670
Re: [Kdawg01] Copying a file and modifying line order output

This will do what you are looking for I think.

Code
 #!/usr/bin/perl   
use strict;
use warnings;

while (<DATA>) {
if (/^n\d+00/) {
my $buffer = $_;
while (<DATA>) {
if (/^m6/) {
print;
last;
}
else {
$buffer .= $_;
}
}
print $buffer;
}
else {
print;
}
}

__DATA__
yabba
n7900889ll some more
text 1
text 2
187.231.45.47 - - www.xyz.com 200 10567 www.abc.com
187.231.45.47 - - www.xyz.com 200 10567 www.ab.com
187.231.45.47 - - www.xyz.com 200 10567 www.ab.com
187.231.45.47 - - www.xyz.com 200 10567 www.c.com
187.231.45.47 - - www.x.com 200 10567 www.abc.com
m6 up to here
dabba

Output

Code
  yabba   
m6 up to here
n7900889ll some more
text 1
text 2
187.231.45.47 - - www.xyz.com 200 10567 www.abc.com
187.231.45.47 - - www.xyz.com 200 10567 www.ab.com
187.231.45.47 - - www.xyz.com 200 10567 www.ab.com
187.231.45.47 - - www.xyz.com 200 10567 www.c.com
187.231.45.47 - - www.x.com 200 10567 www.abc.com
dabba

Update: After reading Kenosis's solution, I realized I could have used more illustrative data. That is, would have showed the solution clearer than my data.


(This post was edited by Chris Charley on Mar 23, 2013, 1:23 PM)


Edit Log:
Post edited by Chris Charley (User) on Mar 23, 2013, 1:22 PM
Post edited by Chris Charley (User) on Mar 23, 2013, 1:23 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives