b10m has a good solution based on a common Unix tool (that's available for other platforms, but not as common on them), but how about a Perl solution?
Here's a one-liner you can use from the command line:
perl -ne 'next if 0 == $. % 25; print' filename
Here's a somewhat clearer version:
#!/usr/local/bin/perl --
use strict;
use warnings;
my $remove_lines_modulo = 25;
while ( <> ) {
next if 0 == $. % $remove_lines_modulo;
print;
}
Or one that accepts an argument for which lines to remove:
#!/usr/local/bin/perl --
use strict;
use warnings;
my $remove_lines_modulo = shift @ARGV;
die "Cannot handle zero as an argument.\n" if 0 == $remove_lines_modul
+o;
while ( <> ) {
next if 0 == $. % $remove_lines_modulo;
print;
}
Please remember that if this is a homework assignment, it's proper form to say so. Asking for completed work instead of help when it's a school assignment doesn't do any good in the long run and isn't fair to students who actually did the work.
-
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.
|