Sh4dow Posted April 13, 2005 Author Share Posted April 13, 2005 Ok, I think it's like this:FINDSTR /I /M /S /C:" rat " *.txt > rat.listFINDSTR /I /M /S /C:" hat " *.txt > hat.listFINDSTR /I /M /S /C:" cat " *.txt > cat.listThen to compare the files to see if it contains 2 or 3 of the words I came up with this:FINDSTR /I /M /S /F:rat.list rat > rat-hat.listFINDSTR /I /M /S /F:hat.list hat > rat-cat.listFINDSTR /I /M /S /F:cat.list cat > hat-cat.list?? Link to comment Share on other sites More sharing options...
purewaveform Posted April 13, 2005 Share Posted April 13, 2005 FINDSTR /I /M /S /F:rat.list rat > rat-hat.listshould beFINDSTR /I /M /S /F:rat.list /C:" hat " > rat-hat.listThat way it will search for the literal " hat " in the rat list, and wala you will have a rat-hat list! Link to comment Share on other sites More sharing options...
Sh4dow Posted April 13, 2005 Author Share Posted April 13, 2005 Purewaveform, not only did you greatly assist me, but I've learned something new. Thank you very much for all of your time. Link to comment Share on other sites More sharing options...
Yzöwl Posted April 13, 2005 Share Posted April 13, 2005 FINDSTR /I /M /S /F:rat.list /C:" hat " > rat-hat.listThat way it will search for the literal " hat " in the rat list, and wala you will have a rat-hat list!What happens if hat is at the beginning or end of a line, there will not be a space on each side of it? Link to comment Share on other sites More sharing options...
purewaveform Posted April 13, 2005 Share Posted April 13, 2005 your right. But that is you can run several other commands, like redo the search and instead of /c:" hat " you can use /b /c:"hat " that way it will only search at the beginning of the line. I will post the complete answer in a an hours or so. Link to comment Share on other sites More sharing options...
staples Posted April 13, 2005 Share Posted April 13, 2005 findstr does not always work. Unfortunately I do this all time. Here is a better solution... more lines but works all the time. find works better. find /i make the search Not case senstive.@echo offfind /i "rat" a.txt >nul if %errorlevel%==0 goto foundaratif %errorlevel%==1 goto noratif %errorlevel%==9009 goto wherefindpausegoto :eof:foundarat echo I found a rat. pausegoto :eof:norat if not exist a.txt echo I cannot find a.txt, so there is no rat. if exist a.txt echo I cannot find a rat. pausegoto :eof:wherefind echo I cannot find find. pausegoto :eof Link to comment Share on other sites More sharing options...
purewaveform Posted April 14, 2005 Share Posted April 14, 2005 just remember that if you were going to do it that way in the last post, then you need to have sections that when found rat you did the sarch in that file to find all occurances of the next word. Here is a copmlete working solutionFINDSTR /I /M /S /C:" hat " *.* > hat.listFINDSTR /I /M /S /B /C:"hat " *.* >> hat.listFINDSTR /I /M /S /E /C:" hat" *.* >> hat.listFINDSTR /I /M /S /C:" cat " *.* > cat.listFINDSTR /I /M /S /B /C:"cat " *.* >> cat.listFINDSTR /I /M /S /E /C:" cat" *.* >> cat.listFINDSTR /I /M /S /C:" rat " *.* > rat.listFINDSTR /I /M /S /B /C:"rat " *.* >> rat.listFINDSTR /I /M /S /E /C:" rat" *.* >> rat.listFINDSTR /I /M /S /C:" cat " /L:hat.list > cat-hat.listFINDSTR /I /M /S /B /C:"cat " /L:hat.list > cat-hat.listFINDSTR /I /M /S /E /C:" cat" /L:hat.list > cat-hat.listFINDSTR /I /M /S /C:" rat " /L:hat.list > rat-hat.listFINDSTR /I /M /S /B /C:"rat " /L:hat.list > rat-hat.listFINDSTR /I /M /S /E /C:" rat" /L:hat.list > rat-hat.listFINDSTR /I /M /S /C:" rat " /L:cat.list > rat-cat.listFINDSTR /I /M /S /B /C:"rat " /L:cat.list > rat-cat.listFINDSTR /I /M /S /E /C:" rat" /L:cat.list > rat-cat.listFINDSTR /I /M /S /C:" hat " /L:rat-cat.list > hat-rat-cat.listFINDSTR /I /M /S /B /C:"hat " /L:rat-cat.list > hat-rat-cat.listFINDSTR /I /M /S /E /C:" hat" /L:rat-cat.list > hat-rat-cat.listThat should find all occurances of hat, cat, rat wether it is at the end, beginning, or in the middle of a line in all files on the computer, not just txt files. (barring any typos) Now this should take a while to run. As for the error in the last post, it should just post it to the command line, not the redirect. Link to comment Share on other sites More sharing options...
Sh4dow Posted April 14, 2005 Author Share Posted April 14, 2005 The above post gets to line 10 and hangs. I then receive errors:FINDSTR: /: ignoredFINDSTR: /h ignoredFINDSTR: /a ignoredFINDSTR: /t ignoredFINDSTR: /. ignoredFINDSTR: /t ignoredNothing happens after that, I think it's stuck in a loop? Link to comment Share on other sites More sharing options...
Yzöwl Posted April 14, 2005 Share Posted April 14, 2005 Try changing the all instances of /L: to /F: in the example, also I think that the 2nd and 3rd lines in each of the last four sections should have >>instead of > for the output file otherwise they will overwrite the last input to it. Link to comment Share on other sites More sharing options...
Sh4dow Posted April 14, 2005 Author Share Posted April 14, 2005 Remember what I am trying to accomplish is not to find a single word, but 2 or 3 of the words within a file then report which files those 2 or 3 words are in. No matter which way I try, I cannot script a solution that works yet Another question. What if the words are not in that order? Will that make a difference?I have 3 test files that read:test1.txt "The cat is named garfield. He is a fat cat."test2.txt "The cat likes to wear a funny hat."test3.txt "The fat cat who likes to wear a funny hat ate the skinny rat."I feel like Dr. Suess! Link to comment Share on other sites More sharing options...
Yzöwl Posted April 14, 2005 Share Posted April 14, 2005 /L -Uses search strings literally./F:file -Reads file list from the specified file> -Directs output creating a new entry>> -Directs output appending to an entryJust try what I said, and see what happens! Link to comment Share on other sites More sharing options...
Sh4dow Posted April 14, 2005 Author Share Posted April 14, 2005 That being said, I edited purewaveform's script to this:FINDSTR /I /M /S /C:" hat " *.* > hat.listFINDSTR /I /M /S /B /C:"hat " *.* >> hat.listFINDSTR /I /M /S /E /C:" hat" *.* >> hat.listFINDSTR /I /M /S /C:" cat " *.* > cat.listFINDSTR /I /M /S /B /C:"cat " *.* >> cat.listFINDSTR /I /M /S /E /C:" cat" *.* >> cat.listFINDSTR /I /M /S /C:" rat " *.* > rat.listFINDSTR /I /M /S /B /C:"rat " *.* >> rat.listFINDSTR /I /M /S /E /C:" rat" *.* >> rat.listFINDSTR /I /M /S /C:" cat " /F:hat.list > cat-hat.listFINDSTR /I /M /S /B /C:"cat " /F:hat.list >> cat-hat.listFINDSTR /I /M /S /E /C:" cat" /F:hat.list >> cat-hat.listFINDSTR /I /M /S /C:" rat " /F:hat.list > rat-hat.listFINDSTR /I /M /S /B /C:"rat " /F:hat.list >> rat-hat.listFINDSTR /I /M /S /E /C:" rat" /F:hat.list >> rat-hat.listFINDSTR /I /M /S /C:" rat " /F:cat.list > rat-cat.listFINDSTR /I /M /S /B /C:"rat " /F:cat.list >> rat-cat.listFINDSTR /I /M /S /E /C:" rat" /F:cat.list >> rat-cat.listFINDSTR /I /M /S /C:" hat " /F:rat-cat.list > hat-rat-cat.listFINDSTR /I /M /S /B /C:"hat " /F:rat-cat.list >> hat-rat-cat.listFINDSTR /I /M /S /E /C:" hat" /F:rat-cat.list >> hat-rat-cat.listWithin my test files, it still doesn't find all instances. Link to comment Share on other sites More sharing options...
Yzöwl Posted April 14, 2005 Share Posted April 14, 2005 So the error is gone then Link to comment Share on other sites More sharing options...
Sh4dow Posted April 14, 2005 Author Share Posted April 14, 2005 Yes the errors are gone, however for some reason the script still doesn't find all instances of the 3 dirty words Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 14, 2005 Share Posted April 14, 2005 (edited) I do not Know If This will Help But This VBS Script might be better For You To Use. I made this script to test for the word cat in a text file called Cat.txt , If the word was there it will add a confirm line in the text file.I tested this in one folder with the file in there, I have included a if not so you dont get the standard error a vbs script makes when it cant find something.I am not a scripter this is from a template on the MSDN site So If There Are Some People Who Have more Knowledge Of VBS Please Help Him Modify It To Suit His Needs. My Brief Break Down Red Is The File It Searches ForBlue Are The Objects needed For The script These are like the things cmd.exe uses for variuos task.Green Is Now The Functions Of The Object madeOrange Is Set objFile to A New Name For The Script To Use It.Purple If InStr(strWordList, strSearchWord) = 0 Then These Are The Condition That must Be True For The Script To WorkGrey Is The Error If The File Is MissingConst ForReading = 1 ' As The name SaysConst ForAppending = 8 'Adds To the File With Out Removing The Existing EntriesConst ForWriting = 2 'This Will Over Right The File With The New Entry Sfile1 = "Cat.txt"Set objFSO = CreateObject("Scripting.FileSystemObject") If ObjFSo.FileExists(Sfile1) Then Set objFile = objFSO.OpenTextFile(Sfile1, ForReading) strWordList = objFile.ReadAll objFile.Close strSearchWord = Vbcrlf & "Cat" & vbCrLf strSearchWord = Vbcrlf & "Hat" & vbCrLf strSearchWord = Vbcrlf & "Rat" & vbCrLf wscript.sleep 125If InStr(strWordList, strSearchWord) = 0 Then msgbox "The Search Word Found",0 +32,"Confirm Word Was There" Set objFile = objFSO.OpenTextFile(Sfile1, ForAppending) objFile.WriteLine Vbcrlf & "Confirm Word Cat Was There" objFile.Close Else If InStr(strWordList, strSearchWord) = 0 Then msgbox "The Search Word Hat Was Found",0 +32,"Confirm Word Was There" Set objFile = objFSO.OpenTextFile(Sfile1, ForAppending) objFile.WriteLine Vbcrlf & "Confirm Word Hat Was There" objFile.Close End If If InStr(strWordList, strSearchWord) = 0 Then msgbox "The Search Word Rat Was Found",0 +32,"Confirm Word Was There" Set objFile = objFSO.OpenTextFile(Sfile1, ForAppending) objFile.WriteLine Vbcrlf & "Confirm Word Rat Was There" objFile.Close End If End IfEnd If If Not ObjFSo.FileExists(Sfile1) Then MsgBox "The Cat.txt Is Missing" End If Hope This Helps Edited April 14, 2005 by gunsmokingman Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now