<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Skynet

    ---------- ---------- 我的新 blog : liukaiyi.cublog.cn ---------- ----------

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks


    對應腳本運用:
      1.  shell  統籌管理 腳本的運行。合理結合 crontab ,  ps -ef ,kill 等命令。
       2.  perl  處理短小快 。
       3.  python 有比較復雜結構和邏輯的。
     
    本文主要介紹 perl 的行級命令使用 ,力求 短 小 快
    #最簡單的
    $ perl -'print "Hello World\n"'

    #處理文件 行
    $ perl --'print $_' file1


    #編碼轉換
    #如果 有需要 在使用下  encode("UTF-8", decode("GBK",$_));在 linux 下默認 utf-8

    perl -MEncode -ne 'print decode("GBK",$_);'  file.txt




    #正則使用
       #  if($_=~/.*\/(.*)$/){  print $1 ;}  這是perl 巨方便的地方 $1 xx  
    # next LINE 跳到下一個循環

    $ perl --'next LINE unless /pattern/; print $_'


    #去除換行 chomp
    perl -'print split(/\n/,"asg\n");'


    #像 awk 一樣 Begin End
    $ perl -ne 'END { print $t } @w = /(\w+)/g; $t += @w' file.txt 

    #像 awk -F"x" 一樣 切割行
    #-a 打開自動分離 (split)  模式
    #@F 為 切割后的 數組

    perl -F'\t' -ane '
     if($F[1]=~/侃侃/ and $F[2]=~/愛情啊/){
          print "$F[3]\t$F[4]\t$F[5]\n"
      }
    ' all2_data.sort.st

    實際處理:
     
    perl -F'\|\|' -ane '
     my $actor,$music ;
     if  ( $F[3] ){
      $music=$F[2];
      $actor=$F[3];
     }else{
      $music=$F[0];
      $actor=$F[1]; 
     }
      $music =~ tr/[A-Z]/[a-z]/;
      $music =~ s/\s*(.*)\s*\(.*\)/\1/g;
      $actor =~ tr/[A-Z]/[a-z]/;
      $actor =~ s/\s*(.*)\s*\(.*\)/\1/g;
    print "$actor-$music\n";
    ' ring.utf8.txt  |sort -u  > ring.actor_music.sort.utf8.txt &
    wc 
    -l ring.actor_music.sort.utf8.txt


    #像 sed 一樣替換
        # -i 和 sed 一樣 perl 輸出會替換調 源 file.txt
    $ perl --pe 's/\bPHP\b/Perl/g' file.txt


    #外部 傳參
    perl -ne'print "$ARGV[0]\t$ARGV[1]\n" ' file.txt 'par1' 'par2'
        #結果 ..  par1     par2 ..



    # 查詢出 重復列 次數,并 列舉出來
    cut -d"     "  -2 .collection_mobile.data |perl -ne '
       END{
         while (($key,$value)=each(%a)){print $key,"=",$value,"\n";};
       }BEGIN{ %a =(); } 
       chomp;
       $a{$_}+=1; 
     
    '
    結果
    Ring=532895
    CRBT=68500
    RingBoxes=880
    Song=96765

     
    #一些實際使用 :)
    find . -name "*.mp3" | perl -pe 's/.\/\w+-(\w+)-.*/$1/' | sort | uniq
       perl -F'\t' -ane 'if($F[1]=~/$ARGV[0]/ and $F[2]=~/$ARGV[1]/){print "$F[3]\t$F[4]\t$F[5]\n"}' all2_data.sort.st '侃侃' '愛情啊'

    #與 find 合用 -e $ARGV[0] 批量 把 excel 倒成 文本 格式
    find . -maxdepth 1 -name "*xls" -exec perl -'
    require("/home/xj_liukaiyi/src/perl/excel/excelUtil.pl");
    my $file=$ARGV[0];
    sub myRead{
      
    my $str = "";
      
    for $tmp(@_){
        
    $str="$str$tmp\t";
      }
      
    $str="$str\n";
      
    system "echo \"$str\" >> $file.data ";
    }
    &parse_excel("$file",0,\&myRead);
    print "$file\n";
    ' {} \;




    參考:
    http://www.ibm.com/developerworks/cn/linux/sdk/perl/l-p101/index.html
    http://bbs.chinaunix.net/viewthread.php?tid=499434





    整理 m.tkk7.com/Good-Game
    posted on 2009-04-01 14:12 劉凱毅 閱讀(1945) 評論(2)  編輯  收藏 所屬分類: perl

    Feedback

    # re: perl 的幸福生活 2009-04-15 11:49 劉凱毅
    所謂的多線程哦
    sed -n '1,1000p' 什么的 就可以了
    :)
    ls mp3/ |sed -n '4000,6000p'|perl -ne '
    require "/home/xj_liukaiyi/src/perl/util/perlUtil.pl";
    my $tmp=$_;
    chomp($tmp);
    my $to="yd_MP3_stereo_48kbps";
    &set_log_input_file("log_mp3_48");
    unless ( (-e "$to/$tmp") && ($tmp=~/.*\..*/) ){
    &system_util("lame -S --resample 44.1 --abr 16 -m s -b 48 \"./mp3/$tmp\" \"./$to/$tmp\" ");
    }
    ' &

      回復  更多評論
      

    # re: perl 使用 2009-09-01 23:46 skynet
    交集
    cat ddata | perl -ne 'BEGIN{
    $p1="p1";
    $p2="p2";

    $ssplit="\t";


    }END{
    my @inter = grep {$a{$_}} keys %b; # 求交集
    print $p1,"=",join(",",keys %a),"\n";
    print $p2,"=",join(",",keys %b),"\n";
    print "交集:",scalar @inter," \n";
    }
    chomp;
    @lis=split /$ssplit/;
    if( $lis[1] eq $p1 ){
    $a{$lis[0]}++;
    }
    if( $lis[1] eq $p2 ){
    $b{$lis[0]}++;
    }

    '
      回復  更多評論
      

    主站蜘蛛池模板: 91在线亚洲精品专区| 亚洲制服丝袜第一页| 2019亚洲午夜无码天堂| 狼色精品人妻在线视频免费| 可以免费观看的国产视频| 在线精品免费视频无码的| 亚洲中文字幕在线乱码| 亚洲人成综合网站7777香蕉| 一级毛片**免费看试看20分钟| 91免费在线播放| 国产精品亚洲产品一区二区三区| 亚洲天堂一区二区三区四区| 一级毛片免费播放视频| 无码日韩人妻av一区免费| 亚洲中文字幕在线第六区| 亚洲人成色777777老人头| 日本免费人成网ww555在线| 国产精品深夜福利免费观看| 亚洲天天做日日做天天欢毛片| 国产成人精品日本亚洲语音| 91视频免费网址| 久久青青草原亚洲av无码| 亚洲不卡在线观看| 国产精品网站在线观看免费传媒| 免费国产真实迷j在线观看| 亚洲性一级理论片在线观看| 9久久免费国产精品特黄| 日韩免费观看一级毛片看看| 久久精品亚洲一区二区三区浴池 | 99久9在线|免费| 亚洲av区一区二区三| 亚洲入口无毒网址你懂的| 波多野结衣免费一区视频 | 亚洲午夜精品一区二区| 成人国产网站v片免费观看| 成人毛片免费观看| 亚洲精品午夜在线观看| 麻豆精品成人免费国产片| 久99精品视频在线观看婷亚洲片国产一区一级在线 | 久久午夜无码免费| 亚洲中文字幕无码爆乳av中文|