suryad Posted April 14, 2005 Share Posted April 14, 2005 THis thread is getting interesting I have to get home and try some of these scripts on my machine. Link to comment Share on other sites More sharing options...
Sh4dow Posted April 15, 2005 Author Share Posted April 15, 2005 The problem I see with the FINDSTR script is the /F command only looks at the file name, not WITHIN the actual file. I need to search for the word " cat " in the files that are in the hat-rat.list. This is getting way more complicated than I originally planned. I do not think that I will be able to complete this task without a lot of help.I also found that if you run the first 9 lines seperately then do not give a correct ouput.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.listThe cat list is the only one that gives true results. The other lines are exactly the same but they do not. I'm so confused!! Link to comment Share on other sites More sharing options...
Yzöwl Posted April 16, 2005 Share Posted April 16, 2005 (edited) The problem I see with the FINDSTR script is the /F command only looks at the file name, not WITHIN the actual file.No it doesn't, it gets the list of files to be searched from a specified file, (in this case hat.list, or whatever.).Anyway back to your problem, I have used regular expressions in the following examples. Basically they mean, e.g. Search for any word beginning with, (\<), xyz and ending with, (\>), xyz."\<xyz\>"Try these lines, obviously changing the search directory C:\WINDOWS\ to suit!FINDSTR /SIM "\<hat\>" "C:\WINDOWS\*.*" >hat.listFINDSTR /SIM "\<cat\>" "C:\WINDOWS\*.*" >cat.listFINDSTR /SIM "\<rat\>" "C:\WINDOWS\*.*" >rat.listFINDSTR /IM "\<cat\>" /F:"hat.list" >hat-cat.listFINDSTR /IM "\<rat\>" /F:"hat.list" >hat-rat.listFINDSTR /IM "\<rat\>" /F:"cat.list" >cat-rat.listFINDSTR /IM "\<rat\>" /F:"hat-cat.list" >hat-cat-rat.listAnd to give the desired result in accordance with your original question you could make do with just thisFINDSTR /SIM "\<hat\>" "C:\WINDOWS\*.*" >hat.listFINDSTR /SIM "\<cat\>" "C:\WINDOWS\*.*" >cat.listFINDSTR /IM "\<cat\>" /F:"hat.list" >hat-cat.listFINDSTR /IM "\<rat\>" /F:"hat.list" >hat-rat.listFINDSTR /IM "\<rat\>" /F:"cat.list" >cat-rat.list Edited April 18, 2005 by Yzöwl Link to comment Share on other sites More sharing options...
Sh4dow Posted April 18, 2005 Author Share Posted April 18, 2005 The script works perfectly for finding cat, hat, and rat. I just need to come up with a way to find cat in the hat list, rat in the hat list, etc..Would it correct the problem if we changed the output of the files to another directory, then ran the search again within that directory?For ex)FINDSTR /SIM "\<hat\>" "*.*" >"C:\My Documents\Results\hat.list"FINDSTR /SIM "\<cat\>" "*.*" >"c:\My Documents\Results\cat.list"FINDSTR /SIM "\<rat\>" "*.*" >"c:\My Documents\Results\rat.list"Now I have a list of cat, hat, rat. But they are just the file names! So if I searched for cat in hat.list I wouldn't find anything because hat.list just contains the names of the files! Link to comment Share on other sites More sharing options...
Yzöwl Posted April 18, 2005 Share Posted April 18, 2005 (edited) I keep on telling you, it is searching through all the files from the list, hat.list, for the string cat, not looking for the string cat in the file hat.list!Are you performing the task by adding all the lines together in a batch if so don't, there is a good chance that the findstr command on the hat.list will start before the hat.list is finished. Just try each of the following lines one by one directly into a cmd window, (waiting for the output files to finish before the next line is entered)FINDSTR /SIM "\<hat\>" "C:\WINDOWS\*.*" >%TEMP%\hat.listFINDSTR /SIM "\<cat\>" "C:\WINDOWS\*.*" >%TEMP%\cat.listFINDSTR /SIM "\<rat\>" "C:\WINDOWS\*.*" >%TEMP%\rat.listFINDSTR /IM "\<cat\>" /F:"%TEMP%\hat.list" >%TEMP%\hat-cat.listFINDSTR /IM "\<rat\>" /F:"%TEMP%\hat.list" >%TEMP%\hat-rat.listFINDSTR /IM "\<rat\>" /F:"%TEMP%\cat.list" >%TEMP%\cat-rat.listFINDSTR /IM "\<rat\>" /F:"%TEMP%\hat-cat.list" >%TEMP%\hat-cat-rat.listYou should see that it does work! Edited April 18, 2005 by Yzöwl Link to comment Share on other sites More sharing options...
Sh4dow Posted April 18, 2005 Author Share Posted April 18, 2005 C:\>FINDSTR /SIM "\<hat\>" "*.*" >hat.listFINDSTR: Cannot open Documents and Settings\LocalService\Local Settings\Application Data\Microsoft\Windows\UsrClass.datFINDSTR: Cannot open Documents and Settings\LocalService\Local Settings\Application Data\Microsoft\Windows\UsrClass.dat.LOGFINDSTR: Cannot open Documents and Settings\LocalService\NTUSER.DATFINDSTR: Cannot open Documents and Settings\LocalService\ntuser.dat.LOGFINDSTR: Cannot open Documents and Settings\NetworkService\Local Settings\Application Data\Microsoft\Windows\UsrClass.datFINDSTR: Cannot open Documents and Settings\NetworkService\Local Settings\Application Data\Microsoft\Windows\UsrClass.dat.LOGFINDSTR: Cannot open Documents and Settings\NetworkService\NTUSER.DATFINDSTR: Cannot open Documents and Settings\NetworkService\ntuser.dat.LOGcan I ignore these? Link to comment Share on other sites More sharing options...
Yzöwl Posted April 18, 2005 Share Posted April 18, 2005 Yes, probably, I'm guessing that they're being protected! Link to comment Share on other sites More sharing options...
clavicle Posted April 18, 2005 Share Posted April 18, 2005 @Sh4dowHave a look at the posthttp://www.msfn.org/board/index.php?showtopic=42248&st=10I have successfully been using this little utility to do the search, replacing and making changes in the new file to edit boot.ini. The utility was provided by dman.Give it a try if it suits you! Link to comment Share on other sites More sharing options...
Sh4dow Posted April 18, 2005 Author Share Posted April 18, 2005 FINDSTR /SIM "\<hat\>" "C:\WINDOWS\*.*" >%TEMP%\hat.listFINDSTR /SIM "\<cat\>" "C:\WINDOWS\*.*" >%TEMP%\cat.listFINDSTR /SIM "\<rat\>" "C:\WINDOWS\*.*" >%TEMP%\rat.listFINDSTR /IM "\<cat\>" /F:"%TEMP%\hat.list" >%TEMP%\hat-cat.listFINDSTR /IM "\<rat\>" /F:"%TEMP%\hat.list" >%TEMP%\hat-rat.listFINDSTR /IM "\<rat\>" /F:"%TEMP%\cat.list" >%TEMP%\cat-rat.listFINDSTR /IM "\<rat\>" /F:"%TEMP%\hat-cat.list" >%TEMP%\hat-cat-rat.listI tried it in cmd and it works.Lines 4-7 give no output.I just want to find cat, hat, rat within one folder. Then find any of the files that have 2 of those words in it. Feel free to write a VB script, I don't care, I just want it to work!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Link to comment Share on other sites More sharing options...
Nilfred Posted April 18, 2005 Share Posted April 18, 2005 Solution:findstr /R /M "hat.*cat hat.*rat cat.*hat cat.*rat rat.*hat rat.*cat" *.txtDownload test suite:findstr.zip Link to comment Share on other sites More sharing options...
Yzöwl Posted April 19, 2005 Share Posted April 19, 2005 Solution:findstr /R /M "hat.*cat hat.*rat cat.*hat cat.*rat rat.*hat rat.*cat" *.txtNice try, but it gives false results and will only work if the search strings are on the same line.It would pick up father as fat, (which mine isn't), polecat as cat (which they aren't, although they do eat catfood) and hatchet as hat, (and I'm not wearing one on my head).I have added a few additional test files below to show you, what I meanfindstr2.zip Link to comment Share on other sites More sharing options...
Martin Zugec Posted April 19, 2005 Share Posted April 19, 2005 Just an idea, did you try to do this through two FOR commands? I mean FOR with cat, hat and cap and FOR with files? I could try to write it down if you would like Link to comment Share on other sites More sharing options...
Yzöwl Posted April 19, 2005 Share Posted April 19, 2005 Yes soulin, the tidiest way to do it, (for a match all strings), would be to take the search strings, write them to a temp file and use that file with the /G switch in a FOR statement. Then you would CALL another FOR statement with that as the input. It does become more tricky in a any two from three permutation, but that would be the way forward.I have a fully working solution, using a single FOR statement utilising similar code as originally suggested by purewaveform. The code although not polished was actually posted in this thread for the entire weekend, but I decided to remove it, as the idea was to allow Sh4dow and other interested parties here to learn something. Although I do feel a little mean about doing it!A problem with writing the script is not that it's hard, it is just that the poster hasn't really told us what it is for? Noone needs to search for those three words in a text file, he's not even checking txt files in his code. If we were to know the layout of the files he's searching and their contents, and what was really being searched, it would possibly make the effort worthwhile. They will most probably be logs of some sort, and possibly be comma, tab or line delimited, tokens and delimiters in the code will very probably save a lot of time and speed up the search process in too.To write what is required would really be better suited to a dedicated scripting forum as opposed to a general Windows XP group, and to be honest with you after yesterdays statement to 'just write one for me!' I'm kind of glad I took down, the solution I had posted. Link to comment Share on other sites More sharing options...
Martin Zugec Posted April 19, 2005 Share Posted April 19, 2005 2Yzowl: Ah, I see... But we could try to kick them to right direction, right? Ok, guys, you can try to do this using few lines of code, we will JUST guide you, ok? This is little bit CHANGED and UNCOMPLETE part of code:<CODE>Set strSearchFor=test.txtfor /f "usebackq " %%i IN (`dir /b`) DO ( Set strCount=0 for /f "usebackq delims=; tokens=1-4" %%a IN (`type %strSearchFor%`) DO ( find /i "%%a" %%i If %%errorlevel%% EQU 0 Call :Count echo %strCount% ) pause ):Countecho %strCount%Set /a strCount=%strCount% + 1echo %strCount%</CODE>You must find what is wrong AND add something to count subprocedure...Lets make this more interesting Link to comment Share on other sites More sharing options...
Sh4dow Posted April 19, 2005 Author Share Posted April 19, 2005 The problem is this, I cannot give the words that I am searching for. I am looking for these words in any file within 300GB of data. I do not want someone to "write one for me." I have been using every possible combination of switches from this page to attempt to do this myself.http://www.fsref.com/pr/dosxp.shtml#findstrThis stuff isn't easy, as I mentioned before. I have never scripted anything. So if I seem frustrated it's only because I have been attempting to do this for 2 weeks and I have not been able to come up with a solution. I feel pretty stupid that you guys can write this script in like 5 minutes yet I've been trying for 2 weeks and can't even figure out a FOR loop.I'm posting here because I need help, and I appreciate everything that you have posted. My boss is on my a** everyday, and I'm working to try to find a solution. 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