in reply to Delete every n line
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Delete every n line
by kana (Initiate) on May 19, 2008 at 07:49 UTC |