Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要使用Windows XP/7批处理文件从txt文件中删除行_Windows_Search_Batch File - Fatal编程技术网

需要使用Windows XP/7批处理文件从txt文件中删除行

需要使用Windows XP/7批处理文件从txt文件中删除行,windows,search,batch-file,Windows,Search,Batch File,我有一个脚本,可以搜索日志文件并找到一个字符串:即“[501005]”不带引号。在某些行中,该字符串后面紧跟一个变量字,即“[501005]RF”。在某些行中,字符串后跟两个空格,然后是一个可变数字,即“[501005]02”。我只需要没有空格的行。我不能只搜索后跟另一个特定字符串的字符串,因为有太多的可能性。我使用 findstr /i /v "] " /c:"[501005" *inputfile* > *outputfile* 如果我删除/v“]”参数,我会得到包含我的字符串的所

我有一个脚本,可以搜索日志文件并找到一个字符串:即“[501005]”不带引号。在某些行中,该字符串后面紧跟一个变量字,即“[501005]RF”。在某些行中,字符串后跟两个空格,然后是一个可变数字,即“[501005]02”。我只需要没有空格的行。我不能只搜索后跟另一个特定字符串的字符串,因为有太多的可能性。我使用

findstr /i /v "]  " /c:"[501005" *inputfile* > *outputfile*
如果我删除/v“]”参数,我会得到包含我的字符串的所有行,因此我知道搜索工作正常。我唯一的障碍就是消除不需要的线路。下面是一个示例(如您所见,行数也是可变的):


这将删除带有空格的行:

findstr /l /v /c:"] " inputfile > outputfile

删除带有两个空格的
[501005]
行:

findstr /vc:"\[501005]  " input.txt>output.txt

天才非常感谢+1.(我没有足够的代表来实际投票:()所以,findstr/r/i“*反斜杠*[501005][^]”?这给了我所有的行,即使没有[501005]。这并没有像预期的那样起作用。
findstr“[501005]”
findstr”[015]”
(Regex)。你最好使用
findstr\[501005]
findstr /l /v /c:"] " inputfile > outputfile
findstr /vc:"\[501005]  " input.txt>output.txt