合并文件有两个文件:如何与线跳跃
文件f1
有一个结构(在#之后是注释这是不是在文件中)
SomeText1 #Section name - one word [a-zA-Z]
acd:some text #code:text - the code contains only [a-z]
opo:some another text #variable number of code:text pairs
wed:text too #in the SomeText1 section are 3 pairs
SomeText2
xxx:textttt #here only 1 code:text pair
SomeText3
zzz:texxxxxxx #here only 1 code:text pair too
和文件f2
什么包含以相同的顺序与上述文件中的下一行:
1000:acd:opo:wed:123.44:4545.23:1233.23 #3 codes - like in the above segment 1
304:xxx:10:11:12.12 #1 code - these lines contains only
4654:zzz:0 #codes and numbers
期望的输出是
SomeText1:1000:acd:opo:wed:123.44:4545.23:1233.23
acd:some text:
opo:some another text:
wed:text too:
SomeText2:304:xxx:10:11:12
xxx:textttt:
SomeText3:4654:zzz:0
zzz:texxxxxxx:
因此需要将f2
中的行添加到“section name”行中。在f2
文件的每一行代码都是相同的代码进行:在f1
文本对有没有不知道如何下手,因为
- 不能使用
paste
命令,因为我没有在两个文件中具有相同的行数,并且 - 不能使用
join
,因为这两个文件中都不是通用键。
所以,当有人告诉我某些算法,如何开始 - 我将自己编程,这样会很开心。
什么?这是编写代码的关键。我强烈建议你自己尝试一下。 – chrsblck