2

I use Windows 7 and often use the FINDSTR command to search in * .log files.

I would like to ask if it is possible to search for whole words only.

Because often when I type:

findstr "su" *.log

I get:

su
super
unsubscribe

etc.

  • 1
    Type `findstr /?` into a Command Prompt window and read the help message very carefully… – aschipfl Aug 27 '20 at 13:47
  • I have voted to close this question, as it is of no use to future readers. You question could have easily been solved by reading the usage information for the specific command you were using. You have therefore made no reasonable attempt at investigating how to perform the task before posting your question. – Compo Aug 27 '20 at 14:43

1 Answers1

2

2 options, depending on the requirements. Consider you want all lines where su is a standalone word in a string:

user can su
su
super
unsubscribe

then run use word boundary with regex:

findstr /rc:"\<su\>" *.log

which will match both:

user can su
su

if however you only want the standalone word in a string su, then use exact match:

findstr /x "su" *.log

add /i if your word needs to be matched in upper, lower or mixed case.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • 1
    @CharlieSorrow: please [read about how to say 'thank you' on SO](https://stackoverflow.com/help/someone-answers) – Stephan Aug 27 '20 at 15:30