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 閱讀(206) 評論(0)  編輯  收藏 所屬分類: Perl

          主站蜘蛛池模板: 山东省| 塔河县| 疏勒县| 广宁县| 泉州市| 左贡县| 安达市| 屯昌县| 墨竹工卡县| 双牌县| 平安县| 肃南| 讷河市| 邛崃市| 富宁县| 于田县| 贺兰县| 西贡区| 普宁市| 光山县| 海阳市| 潜山县| 特克斯县| 宁河县| 泸水县| 云霄县| 耿马| 丰顺县| 汉沽区| 长垣县| 大兴区| 武鸣县| 华宁县| 北安市| 梁山县| 谢通门县| 长宁区| 大连市| 嵊泗县| 政和县| 黄山市|