Computing.Net > Forums > Programming > FINDSTR problem

FINDSTR problem

Reply to Message Icon

Original Message
Name: klint
Date: January 2, 2008 at 06:52:37 Pacific
Subject: FINDSTR problem
OS: Windows XP SP2
CPU/Ram: n/a
Model/Manufacturer: n/a
Comment:

Happy New Year everyone!

I've got a small problem with FINDSTR. How can I get it to find lines beginning with exactly one space, followed by any non-space character?

I've tried this:

findstr /r "^ [^ ]"

but that seems to match all lines. Gnu egrep works with this, why not findstr?


Report Offensive Message For Removal

Response Number 1
Name: IVO
Date: January 2, 2008 at 13:55:04 Pacific
Subject: FINDSTR problem
Reply: (edit)

findstr /R /C:"^ [^ ]"


Report Offensive Follow Up For Removal

Response Number 2
Name: klint
Date: January 2, 2008 at 16:34:02 Pacific
Subject: FINDSTR problem
Reply: (edit)

Thanks! That works!

My problem was caused by the fact I hadn't read the on-line help properly. The /C option is described as "Uses specified text as a literal search string." I thought that implied you couldn't use regular expressions if you used the /C switch. In fact, you can. The /C switch prevents the special treatment of spaces. The space, in effect, is like an OR operator, so without using /C I was searching for a line beginning with either a space or a non-space, which meant every line. After re-reading the help, it became clearer.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: FINDSTR problem

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software