|
发表于 2011-9-17 15:26:48
|
显示全部楼层
保存为脚本, 如:script.pl
script.pl path_to_ur_file
- #!/usr/bin/perl
- $argc = @ARGV;
- if($argc != 2){
- exit 1;
- }
- open $fh, "<", $ARGV[0];
- $match = $ARGV[1];
- $start = undef;
- $end = undef;
- $tmp = tell $fh;
- while(<$fh>){
- if(m/$match/g){
- if($start == undef){
- $start = tell $fh;
- } else {
- $end = $tmp;
- }
- }
- $tmp = tell $fh;
- }
- if($start && $end){
- seek $fh, $start, 0;
- while(<$fh>){
- print $_;
- $tmp = tell $fh;
- if($tmp == $end){
- last;
- }
- }
- } else {
- print "Not Found"
- }
复制代码 |
|