我正在寻找编辑我的1.txt
文件的方法,以查找一个单词并将其替换为相应的单词,2.txt
并添加字符串的其余部分2.txt
。
我有兴趣维护1.txt
文件的顺序。
>title1
ID1 .... rest of string I'm not interested in
>title2
ID2 .... rest of string I'm not interested in
>title3
ID3 .... rest of string I'm not interested in
>title....
但是我想添加我的信息2.txt
。
>ID1 text I want to extract
>ID2 text I want to extract
>ID3 text I want to extract
>IDs....
最后,我希望创建一个具有以下结构的新文件:
>title1
ID1 .... text I want
>title2
ID2 .... text I want
>title3
ID3 .... text I want
>title....
我已经尝试了几个sed命令,但是其中大多数命令都不能完全替换两个文件中的ID#。希望可以在bash中完成
谢谢你的帮助
尝试失败..我的代码是文件1 = cog_anotations.txt,文件2 = Real.cog.txt ID = COG05764,COG 015668等...
sed -e '/COG/{r Real.cog.txt' -e 'd}' cog_anotations.txt
sed "s/^.*COG.*$/$(cat Real.cog.txt)/" cog_anotations.txt
sed -e '/\$COG\$/{r Real.cog.txt' -e 'd}' cog_anotations.txt
grep -F -f cog_anotations.txt Real.cog.txt > newfile.txt
grep -F -f Real.cog.txt cog_anotations.txt > newfile.txt
实线文件1
>Bravo_5
>CDD:223731 COG0658, ComEC, Predicted membrane metalbinding protein l
>Bravo_6
>CDD:223242 COG0164, RnhB, Ribonuclease HII [DNA replication,
>Bravo_7
>CDD:223778 COG0706, YidC, Preprotein translocase subunit YidC .
实线文件2
COG0006 E Xaa-Pro aminopeptidase
COG0706 J Glutamyl- or glutaminyl-tRNA synthetase
COG0164 J tRNA A37 threonylcarbamoyladenosine synthetase subunit
COG0012 J Ribosome-binding ATPase YchF, GTP1/OBG family
COG0013 J Alanyl-tRNA synthetase
和 awk
awk 'NR==FNR{id[$1","]=$0}
NR!=FNR{f=$0; getline; if (id[$2]) print f RS id[$2]}' file2 file1
>Bravo_6
COG0164 J tRNA A37 threonylcarbamoyladenosine synthetase subunit
>Bravo_7
COG0706 J Glutamyl- or glutaminyl-tRNA synthetase
演练
id
从中file2
添加所需文本中的,,
以与其他文件匹配来加载数组
awk 'NR==FNR{id[$1","]=$0}
在第二个文件中,NR!=FNR
抓取第一行f
并跳至第二行getline
NR!=FNR{f=$0; getline;
然后测试以查看id
所需数组中是否存在该对象,(id[$2])
并打印是否存在
if (id[$2]) print f RS id[$2]}' file2 file1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句