The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => The Orphanage => Topic started by: MazeGen on November 02, 2005, 04:11:23 PM

Title: FINDSTR command weird behaviour
Post by: MazeGen on November 02, 2005, 04:11:23 PM
I'm just fighting with batch scripts on my win xp.

Let's consider a tmp.txt file with the following contents:

Quotemasm32\ include

i.e. there is one line with two strings "masm32\" and "include", delimited with a space.

Let's say we want to find this line using FINDSTR command:

QuoteFINDSTR /C:"masm32\ include" tmp.txt

Too bad, FINDSTR cannot find the string! At first, I thought FINDSTR sees the backslash as a metacharacter, but when we try to change the strings to:

Quote
masm32\include
FINDSTR /C:"masm32\include" tmp.txt

it suddenly works, so the backslash is not seen as a metacharacter!

BTW, the /L option doesn't help here too.

Now I'm really confused. Any ideas, guys?

(you can find the FINDSTR description here (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/findstr.mspx))
Title: Re: FINDSTR command weird behaviour
Post by: arafel on November 02, 2005, 04:35:39 PM
you should use double backslash in the search request. i guess single \ followed by a space has some weird meaning to findstr while doing a literal search.
FINDSTR /C:"masm32\\ include" tmp.txt
Title: Re: FINDSTR command weird behaviour
Post by: MazeGen on November 02, 2005, 04:49:53 PM
Well, command line and batch scripts are very underdocumented, so it could be possible...

You're right that double backslash would be working, but the string is variable, not constant, and I never know what combinations have some special meaning. I already spent many hours writing a metacharacter parser (really horrible work!), but I can't get it working. When I almost finished it, I couldn't figure out some weird error... :( that's why I tried to revert to simple literal strings.
Title: Re: FINDSTR command weird behaviour
Post by: MazeGen on November 03, 2005, 01:43:33 PM
I totally forgot about old MS-DOS FIND. It doesn't allow regural expressions, so works better than its extended version, FINDSTR.
I only wonder why FIND has that weird output :(

Quote

---------- TMP.TXT
masm32\ include