sed (另外一门编程语言,独立语法)

image.png
image.pngimage.png

增加

  1. $ cat readme.txt
  2. Welcome to Biotrainee() !
  3. This is your personal account in our Cloud.
  4. Have a fun with it.
  5. Please feel free to contact with me( email to jmzeng1314@163.com )
  6. (http://www.biotrainee.com/thread-1376-1-1.html)
  7. $ cat readme.txt | sed '1a hahaha'
  8. Welcome to Biotrainee() !
  9. hahaha
  10. This is your personal account in our Cloud.
  11. Have a fun with it.
  12. Please feel free to contact with me( email to jmzeng1314@163.com )
  13. (http://www.biotrainee.com/thread-1376-1-1.html)
  14. $ cat readme.txt | sed '1,2i hehehe'
  15. hehehe
  16. Welcome to Biotrainee() !
  17. hehehe
  18. This is your personal account in our Cloud.
  19. Have a fun with it.
  20. Please feel free to contact with me( email to jmzeng1314@163.com )
  21. (http://www.biotrainee.com/thread-1376-1-1.html)

删除

$ cat readme.txt | sed '/^$/d'
    Welcome to Biotrainee() !
    This is your personal account in our Cloud.
    Have a fun with it.
    Please feel free to contact with me( email to jmzeng1314@163.com )
    (http://www.biotrainee.com/thread-1376-1-1.html)
cat readme.txt | sed '/^ \+$/d'  # 只删除有空格的空白行
cat readme.txt | sed '/^ *$/d'   # 删除所有空白行

$ cat readme.txt | sed '2,4c *************'
    Welcome to Biotrainee() !
    *************
    (http://www.biotrainee.com/thread-1376-1-1.html)

$ cat readme.txt | sed -e '2,4i *************' -e '2,4d'
    Welcome to Biotrainee() !  # 先增后删
    *************
    *************
    *************
    (http://www.biotrainee.com/thread-1376-1-1.html)
$ cat readme.txt | sed 's/is/IS/'   ## 三斜杠法
    Welcome to Biotrainee() !
    ThIS is your personal account in our Cloud.
    Have a fun with it.
    Please feel free to contact with me( email to jmzeng1314@163.com )
    (http://www.biotrainee.com/thread-1376-1-1.html)
$ cat readme.txt | sed 's#/#_#2'  ## #号也是分隔符
    Welcome to Biotrainee() !
    This is your personal account in our Cloud.
    Have a fun with it.
    Please feel free to contact with me( email to jmzeng1314@163.com )
    (http:/_www.biotrainee.com/thread-1376-1-1.html)
$ cat readme.txt | sed '1~3s#ee#EE#'  # 只处理1-3行
    Welcome to BiotrainEE() !
    This is your personal account in our Cloud.
    Have a fun with it.
    Please fEEl free to contact with me( email to jmzeng1314@163.com )
    (http://www.biotrainee.com/thread-1376-1-1.html)
$ cat readme.txt | sed 'y/abc/ABC/' # 一对一替换
    WelCome to BiotrAinee() !
    This is your personAl ACCount in our Cloud.
    HAve A fun with it.
    PleAse feel free to ContACt with me( emAil to jmzeng1314@163.Com )
    (http://www.BiotrAinee.Com/threAd-1376-1-1.html)

$ head Data/example.gtf | grep "ee"   # grep 法
$ cat readme.txt | sed -n '/ee/p'    # p法

练习

lQLPDhtq2DgrACnNAsjNBc6wFZc4eQmwLnUCf7o3IIDhAA_1486_712.png

#1
head Data/example.gtf 
#2
head Data/example.gtf |sed 's/HAVANA/ENSEMBL/'
#3
head Data/example.fa| sed '2,$ y/ATCG/TAGC/' > file
#4
head Data/example.fa| sed 's/[A-Z]/\l&/g'
head Data/example.fa| sed 's/[a-z]/\u&/g'