I need to delete all lines between two matched patterns
I need to match a line having words " chkstats to capture " starting from this line
(Say it occurs at line 40) to another line "Failure to pull stats" (which may come in
line no 100) and there is close brace('}") at the next line which also needs to be removed.
In short all lines from 40 to 100 must be deleted in the file.(Including the symbol "}")
I tried the same I can match the pattern in the file but I dont know how to remove the lines..between the matched patterns..Can anyone tell me how to do the same.
Expand|Select|Wrap|Line Numbers
- $dirname="D:\\GTP\\temp";
- open(FH3, ">filelist.txt") || die "Can't create the report file";
- unless (opendir (DIR,"$dirname")){
- print "Can't open the directory $dirname \n";
- exit;
- }
- while ($file = readdir(DIR)){
- print FH3 "$file\n";
- }
- close(FH3);
- open (FH, qq*<filelist.txt*) || die "Can't find the filelist.txt";
- while(chomp( $mfile=<FH>)) {
- if (-e $mfile && $mfile=~/PC/) {
- print "$mfile\n";
- $mbak_file=$mfile. ".bak";
- system("copy $mfile $mbak_file");
- open (FH1,"<$mbak_file");
- open (FH2,">$mfile");
- while (<FH1>) {
- #Pattern matching and deletion should be done here
- print FH2 $_;
- }
- close (FH1);
- close (FH2);
- system("del $mbak_file");
- } else {
- print "\nCan't find the file $mfile. Please verify in the filelist.txt";
- }
- }
- close (FH);