擅长:python、mysql、java
<p>假设您对文件名的顺序编号没有问题:</p>
<pre><code>with open('honeyd.txt', 'r') as infile:
for index, line in enumerate(infile, 1):
with open('test.rule{}'.format(index), 'w') as outfile:
outfile.write('alert {} {} -> {} {}\n'.format(*line.split()))
</code></pre>
<p>这将创建名为<code>test.rule1</code>、<code>test.rule2</code>等的文件</p>