1.

Solve : Findstr s/ "# and other special characters?

Answer»

I've searched this site and others and still can't seem to solve this problem - a newbie problem I'm sure. I've tried /l and /C:string but it doesn't fix the problem either.

I'm searching files for text strings to make sure they've been updated. Unfortunately the strings contain special characters. I've been ABLE to resolve other characters such as %program% by using %%program%% but for some REASON replacing #string with ##string is not working.

I'm running a .bat FILE where I'm trying to find "#Role = VPMADMIN.ADMIN,VPMDESIGNER.VPM" with findstr commands like;
findstr /s "##Role = VPMADMIN.ADMIN,VPMDESIGNER.VPM" fileabc.txt

Also, I'm trying to find "ISPAM9InstallPath=%programfiles%\CAA_APPS\%%DSI%%\intel_a\fileabc.txt"
I'm using find /c "ISPAM9InstallPath=%%programfiles%%\CAA_APPS\%%DSI%%\intel_a\fileabc.txt"
The output shows that it's converted the %% to % but the findstr returns ==1 (not FOUND). I've checked the file and know it's there. (actually I copied the string into the .bat and added the extra %'s).

Any ideas?
(THANKS, Dave)
Use spaces to separate multiple search strings unless the argument is prefixed
with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or
"there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for
"hello there" in file x.y.

\x Escape: literal use of metacharacter x

Code: [Select]C:\>findstr /c:"#Role = VPMADMIN.ADMIN,VPMDESIGNER.VPM" text.txt
#Role = VPMADMIN.ADMIN,VPMDESIGNER.VPM

C:\>findstr /c:"ISPAM9InstallPath=\%programfiles\%\CAA_APPS\\%\%DSI\%\%\intel_a
\fileabc.txt" text.txt
ISPAM9InstallPath=%programfiles%\CAA_APPS\%%DSI%%\intel_a\fileabc.txtWell,,,, The \ worked for the # but not for the %. here is my command and the result;
findstr /s /c:"ISPAM9InstallPath=\%programfiles\%\CAA_APPS\\%DSI\%\intel_a
findstr /s /c:"ISPAM9InstallPath=\\CAA_APPS\\\intel_a\" fileabc.txt

When I use;
findstr /s /c:"ISPAM9InstallPath=%%programfiles%%\CAA_APPS\%%DSI%%\intel_a"
the DOS window shows that it's been changed to;
findstr /s /c:"ISPAM9InstallPath=%programfiles%\CAA_APPS\%DSI%\intel_a"
but it still comes back as "not found".

using the /c: seems to have no effect.
I then tried the /x and changed the search string to just a portion of the string in the target file. It printed the full text to the output file. I would have expected not found because the line contained more characters that that of the search argument.

Keep in mind, I'm not entering these commands from a cmd line interactively, I'm using a .bat file.

I wonder if this has something to do with executing the commands from within a .bat file?
FOUND the problem. Once I used the %% I apparently then needed to also use the \\. Funny thing is that in using \ or \\, the DOS window showed that it was searching for ISPAM9InstallPath=%programfiles%\CAA_APPS\%DSI%\intel_a"

Here's what ended up working.
FINDSTR /S "ISPAM9InstallPath=%%programfiles%%\\CAA_APPS\\%%DSI%%\\intel_a"



Discussion

No Comment Found