循环遍历每一行并在之后删除它
我有一个 MS-DOS 批处理脚本,它为特定文本文件中的每一行执行自定义命令。我希望它在处理后删除每一行,以便下次打开批处理时,我可以从停止的地方恢复它,而无需重新开始并通过相同的行执行循环。这些行只有数字。
file.txt:
76561197967664150
76561197960466635
76561197969570587
76561197978933289
76561198011880885
76561197977884769
76561198010665215
76561198012847269
76561197988209745
76561197991756815
76561197999860750
76561198012060656
76561198020700372
76561198005281666
另外,如果更容易的话,代码也可以在处理后一次删除250行。
I have a MS-DOS batch script that executes a custom command for each line in a specific text file. And I want it to delete each line after processed so that the next time I open the batch I can resume it from where I stopped without starting all over and executing the loop through the same lines. The lines only have numbers.
file.txt:
76561197967664150
76561197960466635
76561197969570587
76561197978933289
76561198011880885
76561197977884769
76561198010665215
76561198012847269
76561197988209745
76561197991756815
76561197999860750
76561198012060656
76561198020700372
76561198005281666
ALSO, if it is easier, the code may also delete 250 lines all at once after processed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不将最后处理的数字写到文件中,而不是从主文件中删除?这会让事情变得简单得多。下次处理该文件时,您将跳过数字,直到找到写入磁盘的数字。
Why not write out the last number you processed to a file instead of deleting from the main file? That would make it much simpler. Next time you process the file, you skip numbers until you find the one you wrote out to disk.
如果您不介意用每个处理过的行重写文件:
注意:如果您真的指的是 MS-DOS(我对此表示怀疑),那么这将不起作用。
if you don't care to rewrite your file with each processed line:
NOTE: if you really mean MS-DOS (which I doubt), this won't work.