我有以下内容的文件(每个文件一行):
<189>162: CSR-1000V: *Sep 27 06:17:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback317, changed state to up <189>165: CSR-1000V: *Sep 27 06:17:07: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback320, changed state to up <189>164: CSR-1000V: *Sep 27 06:17:06: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback319, changed state to up <189>161: CSR-1000V: *Sep 27 06:16:59: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback316, changed state to up<189>163: CSR-1000V: *Sep 27 06:17:04: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loop
我想创建一个python脚本,可以将它们添加到单个文件(output.txt)中,但是我被卡住了,因为我使用for循环,脚本不断地重复添加现有的行
有什么想法吗
多谢各位
可以处理的方法不止一种,但这取决于您的环境:
第一个:读取目录中的文件,并将数据附加到输出文件中。然后,使用pickle或json将已读文件保存在字典中,并保存在光盘上。下次调用代码getc时,解析该列表并跳过保存在该列表中的文件(PS:使用Python进行文件处理,它的用例)
第二个:Pass the newly create files as argument,如果适合您(我对ApacheNIFI一无所知)
第三个:将这些行与输出文件中的行进行比较,但这会降低性能,而且可能非常不可靠
第四个:将已读取的文件移动到子目录中
我会选择方法一,因为它非常简单和直接
编辑: 我做了一段代码(没有测试),如果它不能开箱即用,那么应该清楚该怎么做
Flows 正如您在附件中所看到的,ApacheNIFI中有一个带有“ExecuteScript”处理器的数据管道,我在其中运行上述python代码。我所描述的问题是,文件中的现有行会不断添加
相关问题 更多 >
编程相关推荐