#!/usr/local/bin/perl # deletepattern.pl # open file.txt and # delete rows between BEGIN_PATTERN and END_PATTERN # and then print out to another .txt file $BEGIN_PATTERN="first word or digit or else to delete"; $END_PATTERN="till need to delete "; #just in case must type the file name from stdin, then use # the "$ARGV[0]" #ex: c:\script\deletepattern.pl file1.txt #replace open(FH,"file1.txt") with open(FH,"$file") #die "Usage: $0 filename\n" unless $ARGV[0]; #$file=$ARGV[0]; open(FH,"file1.txt") or die "Cannot open: file1.txt: $!\n"; while() { if(/$BEGIN_PATTERN/) { $is=1; } elsif(/$END_PATTERN/) { $is=0; } next if $is; print; #print out to another file after parse and delete rows #from input file open OUTPUT, ">>file2.txt" or die "Can't open output file: $!"; print OUTPUT; close OUTPUT; } close FH; print "\n";