我有一个文件A.txt和一个文件B.txt。 B.txt文件包含需要放在A.txt文件中每行第4行末尾的字符串列表(每行一个)。将包含在文本文件中的字符串添加到每个第4行的末尾
实施例:
A.TXT(I加入此示例的行号 - 在真实情况下,不存在这样的列):
1 id_line1
2 some text
3 some text
4 some text
5 id_line2
6 some text
7 some text
8 some text
9 id_line3
10 some text
11 some text
12 some text
13 id_line4
14 some text
15 some text
16 some text
B.txt
1 A
2 B
3 C
4 D
所以B.txt比A.txt线包含的线少4倍(每个B.txt线对应于A.txt中的第4线)。
,并在结束时,我想一个C.txt文件:
id_line1_A
some text
some text
some text
id_line2_B
some text
some text
some text
id_line3_C
some text
some text
some text
id_line4_D
some text
some text
some text
我的问题通过使用SED/AWK的B.txt文件是循环。尽管如此,我还可以用更高级的语言来做到这一点(例如pyhton)
任何想法? 感谢
谢谢你的完美。第一个sed技巧是非常好的主意! –