1.

Solve : Using Findstr /x can't find exact match.?

Answer»

When using:

Code: [Select] echo X>>FILE.txt

FINDSTR /x "X" %CD%\file.txt
The echo places a space and newline character after the "X" so when i try and find and exact MATCH it doesn't find it. Is there a way to either:

a) not place a space and newline character when echoing
b) add a space and newline character when using findstr /x

cheers FBWorks fine for me:

Quote

C:\Temp>echo X>>file.txt

C:\Temp>findstr /x "X" file.txt
X

C:\Temp>findstr /x "X" %cd%\file.txt
X

Quote
The echo places a space and newline character after the "X"

How do you know that? I suspect it inserts carriage-return and LINE-feed characters. What version of the command PROMPT are you using?

OK having tried to go through this step by step logically i can't see what's going on... maybe it's something to do with having more than one string in the file my actual code looks like this:

Code: [Select] findstr /x /i %comm% %CD%\users\current\software.dat >num.dat
where %comm% is a user defined variable and the file software contains:

"help
list
telnet
account
bbs
cracker
"
when i write a test script to find out what's wrong it sometimes works and sometimes doesn't

I suspect your right it's probably a carriage return and line-feed and i don't know what version, im using Vista so i guess the latest?I suspect the lines it doesn't work for are the first and last lines. You only have one word per line. Why even use the /x switch? The /i switch makes it case insensitive, which is not an exact match anyway.

Code: [Select]@echo off
set comm=help
findstr /i "%comm%" %CD%\users\current\software.dat >num.dat




Discussion

No Comment Found