sed (另外一门编程语言,独立语法)
增加
$ cat readme.txt
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 '1a hahaha'
Welcome to Biotrainee() !
hahaha
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,2i hehehe'
hehehe
Welcome to Biotrainee() !
hehehe
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'
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法
练习
#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'