我正在尝试删除文件中所有包含某些值的所有行。 我的文件如下所示:
"BLOT" "GL.AC" "00350" "AMG" "10502" " " " " " " " " " " " " "
"ACOD" "BC.FF" "00350" "AMG" "10502" " " " " " " " " " " " " "
"VARC" "DF.RR" "00350" "AMG" "10502" " " " " " " " " " " " " "
想法是删除所有包含字符串“ BLOT”和“ VARC”的行
预期结果是:
"ACOD" "BC.FF" "00350" "AMG" "10502" " " " " " " " " " " " " "
我们如何使用批处理脚本从文件中删除这些行?
我找到了此命令,但这不会删除行
powershell -Command "(gc C:\TEST_AUTO.txt) -replace 'BLOT', 'XXXX' | Out-File myFile.txt"
感谢您的帮助
答案 0 :(得分:1)
最好使用aschipfl所提示的FindStr
命令:
FindStr /V "^\"BLOT\" ^\"VARC\"" "C:\TEST_AUTO.txt">"myfile.txt"
您是否希望使用批处理文件PowerShell
选项?
PowerShell "GC 'C:\TEST_AUTO.txt'|?{$_ -NotMatch '^\"BLOT\"|^\"VARC\"'}|SC 'myfile.txt'"
答案 1 :(得分:0)
问题由usind解决:
查找/ V“ BLOT” C:\ TEST_AUTO.txt> result.txt