Solved Findstr configuration problem exact match

April 3, 2013 at 20:30:31
Specs: Windows 7
Ran into a pretty tough problem.
Here's the snippet:
set /A cnt+=1
for /f "tokens=1 delims=," %%a in ('findstr /C:"!substring%cnt%!" keytable.txt') do echo.%%a>> %tmp%\decoded.txt
if "%cnt%" NEQ "%limit%" Goto :LOOP2

Now the problem is, when cnt is equal to 1, and searches for
396128 without quotes, since %substring1% is equal to that findstr returns with:
Since both contain the same string, now it is obvious the correct one i'm looking for is the second line:6,396128,2916128.
The problem is, how will i configure findstr to search in such a way?
I've just thought of a work around which although slow and ugly would work. If the lines>=2 set the 3 tokens of each line to variables.
Then do a comparison of if "variableline1no1"=="!substring%cnt%!" (
etc... and go through a loop, once correct one is found set the line it came from since there are two different names for each variable, as the string to get the 1st token from.
It is always a variable, the string it searches for since the user will input it, it's a script for a decoder, so placing skip=1 will not help that is the only method which will be reliable otherwise it will be a mess and have many false positives.
keytable.txt contains the real values of each number.
keytable.txt's content is basically values with 2 numbers next to them that they can be translated to e.g:

See More: Findstr configuration problem exact match

Report •

April 3, 2013 at 21:46:34
✔ Best Answer
I think I'm missing something...
for /f "tokens=1 delims=," %%a in ('findstr /C:",!substring%cnt%!" keytable.txt') do

I'm not sure I "have it" right...

Report •

April 4, 2013 at 06:06:38
Nice tweak, it works.

Report •
Related Solutions

Ask Question