2013-01-20 30 views
0

我使用这个命令来滤除线set timing on;Windows批处理:无法筛选出精确匹配的行

type filea.sql | findstr /v "^set timing on;$" 

和输出,我得到如下:

whenever sqlerror exit 9; 

grant select on exfdsfds; 


exit; 

filea.sql的内容是:

set timing on; 
whenever sqlerror exit 9; 

grant select on exfdsfds; 

timing on; cool 

exit; 

为什么删除timing on; cool什么改性中需要ns来命令才能避免这种结果?

回答

3

正如findstr /?记录你需要使用/c如果要包含空格的整个字符串匹配:除非参数有/ C前缀

用空格分隔多个搜索字符串。例如,'FINDSTR'hello there“x.y”在文件x.y中搜索“hello”或“there”。 'FINDSTR/C:“hello there”x.y“在文件x.y中搜索”hello there“。

如果你想使用^$你还需要/r,否则该字符串将被视为文本字符串,而不是一个正则表达式。

type filea.sql | findstr /v /r /c:"^set timing on;$" 

没有/c的命令删除含有任何的从输出,其中包括线timing on; cool因为有用于字timing匹配给定的单词的行。