findstr to find a string contains a phrase

Microsoft Windows ultimate 64-bit 7
February 2, 2010 at 16:48:50
Specs: Windows Server 2008, intel core 2 3.0ghz
I need to check if a string that must contain "I have tested" or must start with "I have tested", for example:
* I have tested .*
or
I have tested .*
but not:
* I have tested
or
I have tested

Somethings have to follow "I have tested"
I made this search string like:

findstr /i /c:"I have tested" >nul
"whatever I have tested" will pass the test.
I tried
findstr /i/r *.* I have tested .* doe snot work.
Can anyone help me? Thank you!
Best Regards
Lynda


See More: findstr to find a string contains a phrase

Report •

#1
February 2, 2010 at 18:04:41
So does the string have to be at the beginning of the line, the end of the line, both or something else?

"I need to check if a string that must contain "I have tested" or must start with "I have tested","

Which is it? If it starts with "I have tested" then it must contain "I have tested"



My boring little personal page(in progress)


Report •

#2
February 2, 2010 at 18:36:44
in other words, the literal has to have at least one byte of text following it, right? that seems the most succinct way of stating the criteria...
if that is correct, this might work:
findstr /i /r "I have tested."
(edited)

Report •

#3
February 3, 2010 at 07:26:35
Seemed easy at first, but can't get it going either ... the dot can also mean no character at all ... which is the case when it is at the end of the line.

Lynda, the C is a literal expression (no use of wildcards, all characters as written literally), the R is what you need, since you need to specify some form of wildcards.

edit : ... got it :

@echo off

findstr /I /C:"I have tested" test.txt > temp01.txt
findstr /I /V /E /R "I have tested" temp01.txt

Not sure how to do it with one command, so taking two. The V is for all lines NOT matching, the E means "at the End". Maybe line 2 can also be done with C instead of R

edit 2:
Well .. this way:

@echo off

findstr /I /C:"I have tested" test.txt | findstr /I /V /E /C:"I have tested"


Report •

Related Solutions

#4
February 3, 2010 at 09:04:45
Thank you very much ! tvc's solution works:
findstr /I /C:"I have tested" test.txt | findstr /I /V /E /C:"I have tested" temp01.txt


Sorry to reply you late. I was not around computer after work.
nbrane summarize it well:
" the literal has to have at least one byte of text following it"
English is my second language, some times just don't know how to express it.
Thank you all! This is the best forum I ever had!
Lynda


Report •

#5
February 3, 2010 at 09:13:30
Made one small mistake, command is in fact :

findstr /I /C:"I have tested" test.txt | findstr /I /V /E /C:"I have tested"

The last mentioning of a file, does not need to be there, but it does not seem to produce an issue (but note he is reading test.txt).

The /I means case insensitive, you may not need it, or you do


Report •

#6
February 3, 2010 at 10:27:16
Thank you!
In my code, I used it as
" svnlook log %REPOS% -t %TRANSACTION% | findstr /i /c:"I have tested" | findstr /I /V /E /R "I have tested" >nul"
log ( same as the text.txt) is the file to be checked if it contains string "I have tested". I assumed above code is a pipe. Is that right? I tested it. It works fine. Thank you again for your great help!
Best Regards
Lynda

Report •

Ask Question