我有一个包含以下内容的文件:
set0027:
set0027_100-250
set0027_1-150
set0027_50-200
set0038:
set0038_100-250
set0038_1-150
set0038_50-200
我想按照以下方式修改它:
cd set0027
clustalw INFILE=set0027_100-250 OUTFILE=set0027_100-250.aln
clustalw INFILE=set0027_1-150 OUTFILE=set0027_1-150.aln
clustalw INFILE=set0027_50-200 OUTFILE=set0027_50-200.aln
cd ..
cd set0038
clustalw INFILE=set0038_100-250 OUTFILE=set0038_100-250.aln
clustalw INFILE=set0038_1-150 OUTFILE=set0038_1-150.aln
clustalw INFILE=set0038_50-200 OUTFILE=set0038_50-200.aln
cd ..
我如何使用 bash 脚本来做到这一点?
答案1
类似这样的事情会起作用:
$ perl -npe 's/(.*):/cd \1/; s/^(set.*)/clustalw INFILE=\1 OUTFILE=\1.aln/; s/^\s+/cd ..\n/;' file
cd set0027
clustalw INFILE=set0027_100-250 OUTFILE=set0027_100-250.aln
clustalw INFILE=set0027_1-150 OUTFILE=set0027_1-150.aln
clustalw INFILE=set0027_50-200 OUTFILE=set0027_50-200.aln
cd ..
cd set0038
clustalw INFILE=set0038_100-250 OUTFILE=set0038_100-250.aln
clustalw INFILE=set0038_1-150 OUTFILE=set0038_1-150.aln
clustalw INFILE=set0038_50-200 OUTFILE=set0038_50-200.aln
使用命令行选项
-n implicit loop
-e execute perl inline
-p print line