#!/usr/bin/perl -w # remove lines matching pattern from each file. # usage: dline PATTERN FILES use Tie::File; use strict; my $file; my $k; my @match; my @lines; my $pat = shift || die "no pattern"; foreach $file (@ARGV) { tie(@lines, 'Tie::File', "$file") or die "$file: can't update"; @match = (); $k = 0; for (@lines) { push(@match, $k) if /$pat/; $k++; } # Walk the matches backwards so we don't throw the numbering # off. Using "delete $lines[$k]" will keep a blank line. while ($k = pop(@match)) { splice(@lines, $k, 1); } untie @lines; } exit(0);