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.


In reply to Re: Delete every n line by mr_mischief
in thread Delete every n line by kana

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.