Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
# Choose the Nth FASTA record # Called as "perl script_name.pl line_number file_name" use warnings; use strict; $/= '>'; my $line_number = shift; while(<>) chomp; if ($.-1 == $line_number ) { print; exit 0; } }
# Choose any Range of FASTA records # Called as perl script_name.pl --start start_line --end end_line file +_name # both --start and --end are optional; # no --start => start reading from end of file, end at --end # no --end => start reading from --start, read to end of file # neither => print every line use warnings; use strict; use Getopt::Long; my ($start, $end) = (undef, undef); GetOptions( "start=i" => \$start, "end=i" => \$end, ); $/='>'; while(<>) { if( (!defined($start) || $start <= $.) && (!defined($end) || $. <= $end) ) { print; }
In reality, the second script subsumes the first as a special case (set start and end to the same value).

As for your "show the number of lines" example, I don't understand it. From the looks of it, it looks like it counts the number of lines in the file that have a whitespace character in it. Is this really what you want?

thor

The only easy day was yesterday


In reply to Re^6: Private Utilities by thor
in thread Private Utilities by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-28 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found