美文网首页
Shell实用——统计字符种类及个数

Shell实用——统计字符种类及个数

作者: 是杰宝呀 | 来源:发表于2018-08-12 18:15 被阅读67次

    1. 前期准备

    • 数据下载

      $ wget -c ftp://hgdownload.cse.ucsc.edu/goldenPath/sacCer3/bigZips/mrna.fa.gz
      $ wget -c ftp://hgdownload.cse.ucsc.edu/goldenPath/sacCer3/bigZips/mrna.fa.gz.md5
      
    • 数据完整性校验

      $ md5sum --check mrna.fa.gz.md5
      mrna.fa.gz: OK
      
    • 了解fasta格式,提取序列

      $ gunzip -c mrna.fa.gz | grep -v "^>" > data.fa
      

    2. 脚本编写

    test.sh

    #!/bin/bash
    
    for i in {a..z}
    do
        grep -q $i data.fa;
        if [ $? == 0 ]; then 
            n=`grep -o $i data.fa | wc -l`;
            printf "$i\t$n\n";
        fi
    done 
    

    3. 脚本运行

    $ bash test.sh
    a       98378
    b       1
    c       59955
    d       21
    g       65147
    n       866
    r       1
    s       2
    t       89401
    w       1
    y       1
    

    相关文章

      网友评论

          本文标题:Shell实用——统计字符种类及个数

          本文链接:https://www.haomeiwen.com/subject/lbzsbftx.html