in reply to How to delete mutiple line from many pm files at one time
Do you mean that you want to remove the code lines you show from all of the *.pm files? If so, you could so this with in-place editing and a flip-flop (..) operator. You have to make sure you escape any regular expression meta-characters in the code lines you use to delineate start and end of the section to remove.
knoppix@Microknoppix:~/perl/Monks$ ls d971401/ File1.pm File2.pm File3.pm File4.pm File5.pm knoppix@Microknoppix:~/perl/Monks$
knoppix@Microknoppix:~/perl/Monks$ head -99 d971401/* ==> d971401/File1.pm <== package File1; Some lines of code here my $t0 = [gettimeofday]; my $time = tv_interval ( $t0, [gettimeofday]); my @timeData = localtime(time); $time= join(':', @timeData); if($time =~m#^(.*?)\:(\d+)\:(\d+).*?$#) { $time = $3 . ':' . $2 . ':' . $1; } more code here 1; ==> d971401/File2.pm <== package File2; Some lines of code here my $t0 = [gettimeofday]; my $time = tv_interval ( $t0, [gettimeofday]); my @timeData = localtime(time); $time= join(':', @timeData); if($time =~m#^(.*?)\:(\d+)\:(\d+).*?$#) { $time = $3 . ':' . $2 . ':' . $1; } more code here 1; ==> d971401/File3.pm <== package File3; Some lines of code here my $t0 = [gettimeofday]; my $time = tv_interval ( $t0, [gettimeofday]); my @timeData = localtime(time); $time= join(':', @timeData); if($time =~m#^(.*?)\:(\d+)\:(\d+).*?$#) { $time = $3 . ':' . $2 . ':' . $1; } more code here 1; ==> d971401/File4.pm <== package File4; Some lines of code here my $t0 = [gettimeofday]; my $time = tv_interval ( $t0, [gettimeofday]); my @timeData = localtime(time); $time= join(':', @timeData); if($time =~m#^(.*?)\:(\d+)\:(\d+).*?$#) { $time = $3 . ':' . $2 . ':' . $1; } more code here 1; ==> d971401/File5.pm <== package File5; Some lines of code here my $t0 = [gettimeofday]; my $time = tv_interval ( $t0, [gettimeofday]); my @timeData = localtime(time); $time= join(':', @timeData); if($time =~m#^(.*?)\:(\d+)\:(\d+).*?$#) { $time = $3 . ':' . $2 . ':' . $1; } more code here 1; knoppix@Microknoppix:~/perl/Monks$
knoppix@Microknoppix:~/perl/Monks$ perl -ni.BAK -e ' print unless m{^my \$t0 = \[gettimeofday\];} .. m{^\s+\}};' d971401/*. +pm knoppix@Microknoppix:~/perl/Monks$ ls d971401/* d971401/File1.pm d971401/File3.pm d971401/File5.pm d971401/File1.pm.BAK d971401/File3.pm.BAK d971401/File5.pm.BAK d971401/File2.pm d971401/File4.pm d971401/File2.pm.BAK d971401/File4.pm.BAK knoppix@Microknoppix:~/perl/Monks$
knoppix@Microknoppix:~/perl/Monks$ head -99 d971401/*.pm ==> d971401/File1.pm <== package File1; Some lines of code here more code here 1; ==> d971401/File2.pm <== package File2; Some lines of code here more code here 1; ==> d971401/File3.pm <== package File3; Some lines of code here more code here 1; ==> d971401/File4.pm <== package File4; Some lines of code here more code here 1; ==> d971401/File5.pm <== package File5; Some lines of code here more code here 1; knoppix@Microknoppix:~/perl/Monks$
I hope that I have guessed correctly and that this is helpful.
Cheers,
JohnGG
|
|---|