Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: searching for multiple lines from outfile and printing them all in the final outfile

by lakshmananindia (Chaplain)
on May 16, 2009 at 04:03 UTC ( [id://764386]=note: print w/replies, xml ) Need Help??


in reply to searching for multiple lines from outfile and printing them all in the final outfile

What advise you need??

What is the problem with your code??

--Lakshmanan G.

The great pleasure in my life is doing what people say you cannot do.


Replies are listed 'Best First'.
Re^2: searching for multiple lines from outfile and printing them all in the final outfile
by Anonymous Monk on May 16, 2009 at 04:14 UTC

    thanks for responding

    suppose say my output file has 100 lines.but out if 100 lines I just want 10 lines that I need to be printed in my final output file.I want to search for all 10 lines and print it in a saperate final file.

    i know how to search for 1 line and print it in final output file but not miltiple lines in my final output file.

    my current code only searches for one line and prints it in final output file

    could you please advice how to do that/? Thanks!
      The canonical way is:
      open my $in_file, '<', 'some_file.txt' or die "$!\n"; while (my $line = <$in_file>) { chomp($line); # If necessary print if $line =~ /foo/; # Or some other conditional }
      Update:Note that in the above example you wouldn't actually want the chomp, but it's usually a good idea if you are doing more than just printing matching lines.

      Regards,
      Darren

      If the lines you require are consecutive, then you could use the range operator to do it along the lines of i.e. untested...
      use warnings; use strict; use autodie; open INFILE, "<infile"; open OUTFILE, ">outfile"; while (<INFILE>) { print OUTFILE if /start regex/ .. /end regex/; } close INFILE; close OUTFILE;
      A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://764386]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-19 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found