batch file search for word at end of sentence

January 7, 2011 at 20:13:18
Specs: Windows Vista
Hello
I have text file called test.txt that contains the following:
HOW ARE YOU TODAY
and i'm trying to write a batch file that searches test.txt for the word "TODAY" and returns the directory of the file if the word is found.
but i only want it to detect the word if it is at the end of the line.

this is what i have so far:

@echo off
findstr /i /m /e "\<today\>" c:\users\me\desktop\test.txt
pause

but it never returns anything even when the word "TODAY" is at the end of a line
please help.


See More: batch file search for word at end of sentence

Report •


#1
January 7, 2011 at 21:17:51
Add an empty line to the end of the file or pipe type into findstr.


The below should work either way:

type "c:\users\me\desktop\test.txt" | findstr /i /m /e "\<today\>"

It won't give you the filename, but you presumably already have it so you can use the return code instead.


Report •

#2
January 7, 2011 at 21:31:13
thanks very much, your solution works perfectly!
i can just add an empty line with "echo. >> (directory)"
so once again, thanks!

Report •

#3
January 7, 2011 at 21:38:09
No problem ;)

Report •

Related Solutions


Ask Question