weidagang2046的专栏

物格而后知致
随笔 - 8, 文章 - 409, 评论 - 101, 引用 - 0
数据加载中……

文本处理小脚本

 

#!c:/perl/bin/perl

# Perl script that will take as input from a file, produce as output to STDOUT; 
# lines in input will be copied to ouput, except for the following transformations:
#
# 1.    any line with the string "IgNore" in it will not go to output
# 2.    any line with the string "#" in it will have that character and all characters
#        after it, to end of line, removed
# 3.    any string "*DATA*" will be replaced by the current date in output


$arg_num = @ARGV;

(
$arg_num > 0|| die ("No file specified to be processed\n");

open(INFILE, $ARGV[0]) || die ("Can not open file $ARGV[0]");

chop($date = `date`); #run system command, remove newline at the end

while($line = <INFILE>)
{
    
if($line =~ /IgNore/)
    {    
        
next;
    }
    
$line =~ s/\*DATE\*/$date/g;
    
if($line =~ /([^\#]*)\#.*/)
    {
        
$line = $1;
    }
    
print $line;
}

close(INFLIE); #don't forget to close it

posted on 2006-03-05 11:59 weidagang2046 阅读(192) 评论(0)  编辑  收藏 所属分类: Perl


只有注册用户登录后才能发表评论。


网站导航: