我有一個文件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技巧是非常好的主意! –