使用批处理删除文本文件中的条目

时间:2013-01-30 07:58:35

标签: batch-file

例如,如果我使用findstr /g:Filters/test.ini < "ServerLogs/users.log" > "Logs/filtered_users.txt

我想首先搜索并记下该行,然后删除/覆盖一行,例如“ServerLogs / users.log”

我需要设置什么?

例如:“ServerLogs / users.log”

JacktheRiver IP:18.184.284.91 - SETPATHDOWN 394858913857869284 #10 39485918238584378
Laste3r IP:72.125.68.141 - SETPATHDOWN 346343253563467578 #22 35354634679795373
Rus48rr IP:63.215.154.23 - SETPATHDOWN 543534694689128453 #12 49348376384678221
TOkiN1 IP:54.132.146.41 - SETPATHDOWN 343543346363643644 #41 42395833891883585

然后举个例子。 Rus48rr IP:63.215.154.23 - SETPATHDOWN 543534694689128453 #12 49348376384678221并将其保存到“filtered_users.txt”中。从“ServerLogs / users.log”中删除此行后,它最终会像这样:

JacktheRiver IP:18.184.284.91 - SETPATHDOWN 394858913857869284 #10 39485918238584378
Laste3r IP:72.125.68.141 - SETPATHDOWN 346343253563467578 #22 35354634679795373
TOkiN1 IP:54.132.146.41 - SETPATHDOWN 343543346363643644 #41 42395833891883585

这是可能的,如果是的话怎么样?

1 个答案:

答案 0 :(得分:1)

您可以找到匹配的行:

findstr /g:Filters/test.ini < "ServerLogs/users.log" > "Logs/filtered_users.txt"

,您可以找到与/v参数不匹配的行:

findstr /g:Filters/test.ini /v < "ServerLogs/users.log" > "ServerLogs/users.tmp"

然后,您可以使用新的users.log文件覆盖users.tmp