To All:
The problem originated from a topic by bsijl about incorrect filtering with findstr . At that time, since the cause couldn't be found, we could only speculate that there were certain issues with the /g switch.
Recently, when writing a debugger code, I used findstr/g again and encountered the same problem . After careful testing , it was found that the problem was caused by the special command-line parsing mechanism of findstr. Briefly described as follows:
1. Unlike the early find, findstr has certain requirements for the arrangement of parameters, that is, it follows the order of switches (can be omitted), strings (omitted when using the /c switch), and file names (can be wildcards, can be multiple, and need to be omitted when there is an input stream).
2. Switches can use quotes, so you can't directly search with keywords the same as switches; file names with spaces must use quotes.
3. The situation and performance of search keywords are relatively complicated, described as follows:
3-1. Whether using the /l or /r switch or using quotes, \ in the keyword will become an escape character, so \\ will become \, and \" will make the quote lose the string delimiting function;
3-2. Search keywords can be with or without quotes. When with quotes, \ in them may be escaped again. The escape results when using /l and /r switches may be different: when using /r, so "\\\\" will become a single \, and "\\" will make the keyword empty; when using /l or neither, "\\\\" and "\\" are equivalent to a single \.
3-3. If the keyword ends with a single \ and has no quotes, it will not be escaped;
And the problem with findstr/g should be related to the above content, but the internal mechanism is still not thoroughly understood. I wonder what everyone's opinions are?
Batch processing to delete XP input method problem! Please DOS experts solve
http://www.cn-dos.net/forum/search.php?searchid=24472
Test of findstr/v/g
Test of findstr
[ Last edited by willsort on 2006-6-11 at 18:38 ]
The problem originated from a topic by bsijl about incorrect filtering with findstr . At that time, since the cause couldn't be found, we could only speculate that there were certain issues with the /g switch.
Recently, when writing a debugger code, I used findstr/g again and encountered the same problem . After careful testing , it was found that the problem was caused by the special command-line parsing mechanism of findstr. Briefly described as follows:
1. Unlike the early find, findstr has certain requirements for the arrangement of parameters, that is, it follows the order of switches (can be omitted), strings (omitted when using the /c switch), and file names (can be wildcards, can be multiple, and need to be omitted when there is an input stream).
2. Switches can use quotes, so you can't directly search with keywords the same as switches; file names with spaces must use quotes.
3. The situation and performance of search keywords are relatively complicated, described as follows:
3-1. Whether using the /l or /r switch or using quotes, \ in the keyword will become an escape character, so \\ will become \, and \" will make the quote lose the string delimiting function;
3-2. Search keywords can be with or without quotes. When with quotes, \ in them may be escaped again. The escape results when using /l and /r switches may be different: when using /r, so "\\\\" will become a single \, and "\\" will make the keyword empty; when using /l or neither, "\\\\" and "\\" are equivalent to a single \.
3-3. If the keyword ends with a single \ and has no quotes, it will not be escaped;
And the problem with findstr/g should be related to the above content, but the internal mechanism is still not thoroughly understood. I wonder what everyone's opinions are?
Batch processing to delete XP input method problem! Please DOS experts solve
http://www.cn-dos.net/forum/search.php?searchid=24472
Test of findstr/v/g
E:\Batch\Test>set > envar.out
E:\Batch\Test>findstr /v /g:envar.out envar.out
LOGONSERVER=\\Test
ProgramFiles=C:\Program Files
E:\Batch\Test>findstr /v /i /g:envar.out envar.out
LOGONSERVER=\\Test
Test of findstr
:: Test of findstr
:: Will Sort - 2006-06-10 - CMDWinXP
@echo off
cls&echo ---- "set>_tfs1.tmp & findstr /v /g:_tfs1.tmp _tfs1.tmp"
set>_tfs1.tmp & findstr /v /g:_tfs1.tmp _tfs1.tmp
pause
echo ---- "findstr /v /i /g:_tfs1.tmp _tfs1.tmp"
findstr /v /i /g:_tfs1.tmp _tfs1.tmp
pause
echo ---- "sort /r _tfs1.tmp > _tfs2.tmp & findstr /v /g:_tfs1.tmp _tfs2.tmp"
sort /r _tfs1.tmp > _tfs2.tmp & findstr /v /g:_tfs1.tmp _tfs2.tmp
pause
echo ---- "set|findstr /v /g:_tfs1.tmp"
set|findstr /v /g:_tfs1.tmp
pause
cls&echo ---- "dir C:\ /w > _tfs2.tmp & findstr /v /g:_tfs2.tmp _tfs2.tmp"
dir C:\ /w > _tfs2.tmp & findstr /v /g:_tfs2.tmp _tfs2.tmp
pause
echo ---- "echo :\ > _tfs2.tmp & findstr /v /g:_tfs2.tmp _tfs2.tmp"
echo :\ > _tfs2.tmp & findstr /v /g:_tfs2.tmp _tfs2.tmp
pause
cls&echo ---- "findstr /g:_tfs1.tmp _tfs1.tmp>_tfs2.tmp & fc _tfs1.tmp _tfs2.tmp"
findstr /g:_tfs1.tmp _tfs1.tmp>_tfs2.tmp & fc _tfs1.tmp _tfs2.tmp
pause
cls&echo ---- "set|findstr /r "\\\\ \\\\""
set|findstr /r "\\\\ \\\\"
pause
echo ---- "set|findstr /l "\\\\ \\\\""
set|findstr /l "\\\\ \\\\"
pause
cls&echo ---- "echo _tfs1_tmp > _tfs1.tmp & findstr "/l" "_tfs1.tmp" "_tfs1.tmp""
echo _tfs1_tmp >> _tfs1.tmp & findstr "_tfs1.tmp" "_tfs1.tmp"
pause
del _tfs?.tmp
[ Last edited by willsort on 2006-6-11 at 18:38 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!

DigestI