【发布时间】:2020-10-01 08:52:03
【问题描述】:
我想编辑我的 1.txt 文件,找到一个单词并将其替换为 2.txt 中的对应单词,并添加文件 2 的其余字符串。
我有兴趣维护我的 1.txt 文件的顺序。
>title1
ID1 .... rest of string im not interested
>title2
ID2 .... rest of string im not interested
>title3
ID3 .... rest of string im not interested
>title....
但我想添加我的文件2的信息
>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
【问题讨论】:
-
向我们展示您的失败尝试