我有一个如下所示的输入文件:
input.txt
THISISANEXAMPLEOFANINPUTFILEWITHALONGSTRINGOFTEXT
我有另一个文件,其中有我要更改的字母位置和我要更改的字母位置,例如:
textpos.txt
Position Text_Change
1 A
2 B
3 X
(实际上会有大约10000个字母的变化)
我希望每个文本更改都有一个单独的输出文件,如下所示:
output1.txt
AHISISANEXAMPLEOFANINPUTFILEWITHALONGSTRINGOFTEXT
下一个:
output2.txt
TBISISANEXAMPLEOFANINPUTFILEWITHALONGSTRINGOFTEXT
下一个:
output3.txt
THXSISANEXAMPLEOFANINPUTFILEWITHALONGSTRINGOFTEXT
我想学习如何在一个awk命令和Python的方式,以及如何做到这一点,并想知道什么是最好的,最快的方式做到这一点?你知道吗
提前谢谢。你知道吗
请您尝试以下操作(考虑到您的实际输入文件中会包含相同类型的数据)。这个解决方案应该处理错误
Too many open files error while running awk command
,因为我正在关闭awk
代码中的输出文件。你知道吗3个名为
output1.txt
、output2.txt
和output3.txt
的输出文件及其内容如下。你知道吗解释:在此处添加上述代码的解释。你知道吗
使用awk,对第二个文件滥用
FS=""
,使每个字母成为自己的一列:另一种方法是使用
for
和substr
从a[]
和$0
逐字符构建变量:使用gawk:
相关问题 更多 >
编程相关推荐