Batch File! Scripting
#1
Posted 12 April 2005 - 09:08 AM
hat, cat, rat
It can be 3 different searches, but must report the file name if it has TWO of the words. It can have all 3 of the words as well.
I know this is probably easy, but I've never written a batch file before. Can anyone assist me?
Thank you!
#2
Posted 12 April 2005 - 10:32 AM
here is an example to search your entire harddrive for "rat" in all text files and only display the text finle name.
c:\>FINDSTR /S /L /M rat *.txt
You start the loop by looking at the above file, maybe something like a pipe or a redirect, you will need to learn the diffrence, into the same command again. This way you will search for the files that have the next word. Or just get the first list of rat and send all the filenames into a tmp file by taking the output of the command > and redirecting it to a file. Then loop through that list.
OR if you use something like
c:\>FINDSTR /S /L /M .at *.txt
Then you would search for any occurance of three letter words that end in at. then just compare the output
Or remember that findstr can read in for console with /F:/
Here is an example
c:\>FINDSTR /S /L /M a *.txt > a.list C:\>FINDSTR /S /L /M /F:a.list b > a-b.list
The above command will search for all .txt files on the computer with the letter a and then write a file list to the hd and then second command will search that list of files for the letter b and write that result to the file a-b.list
Now remember that with three words you have several combinations.
words a, b, c
combinations include
a - b,
a - c,
b - c,
and then if you want a list of all three you need
a - b -c
I want you to post the final result when you get it. You should have everything you need here.
#3
Posted 12 April 2005 - 11:17 AM
#4
Posted 12 April 2005 - 12:31 PM
#5
Posted 12 April 2005 - 12:55 PM
#6
Posted 12 April 2005 - 01:05 PM
ok here goes:
FINDSTR /s /l /m rat *.txt > a.list
FINDSTR /s /l /m hat *.txt > b.list
FINDSTR /s /l /m cat *.txt > c.list
C:\>FINDSTR /S /L /M /F:a.list b > a-b.list
C:\>FINDSTR /S /L /M /F:a.list c > a-c.list
c:\>FINDSTR /S /L /M /F:b.list c > b-c.list
????????
#7
Posted 12 April 2005 - 02:09 PM
If someone tells me where they want me to put some knowledge then just ask, be happy to help.
As for the quesiton.
Quote
FINDSTR /s /l /m hat *.txt > b.list
FINDSTR /s /l /m cat *.txt > c.list
C:\>FINDSTR /S /L /M /F:a.list b > a-b.list
C:\>FINDSTR /S /L /M /F:a.list c > a-c.list
c:\>FINDSTR /S /L /M /F:b.list c > b-c.list
The first three lines are perfect, you will find all occurances of rat in a.list, hat in b.list, and cat in c.list. Now the next three lines need some help. then you do findstr you need to still tell it what you are looking for. In line 4, you are telling it to look for the letter b in a.list. I think that you want to be looking for hat, not a like this.
C:>\FINDSTR /S /L /M /F:a.list hat > a-b.listthen just repeat for the other entries, in lines 5, 6 you are looking for the string "c" If you changes the c to cat etc, you will have the right answers!
Tell me how it goes!
#8
Posted 12 April 2005 - 02:11 PM
From These Location C:\;D:\;E:\;F:\;G:\;I:\, This Took A While To Complete It Search
Quote
Echo off && CLS && Color 5e && Mode 55,5 && Title Search For Cmd
FINDSTR /S /L /D:C:\;D:\;E:\;F:\;G:\;I:\ /M a *.cmd > cmd.txt
Echo Searching For All CMD && Ping -n 3 127.0.0.1>nul
cls && Color 4e && Title Search For Vbs
FINDSTR /S /L /D:C:\;D:\;E:\;F:\;G:\;I:\ /M a *.vbs > vbs.txt
Echo Searching For All VBS && Ping -n 3 127.0.0.1>nul
goto EOF
exit
This post has been edited by gunsmokingman: 12 April 2005 - 02:22 PM
#9
Posted 12 April 2005 - 02:18 PM
#10
Posted 12 April 2005 - 11:12 PM
For starters I found this link that has a reference of the command shell commands here:
Command line commands
#11
Posted 13 April 2005 - 12:44 AM
#12
Posted 13 April 2005 - 07:34 AM
FINDSTR /s /l /m "hat" *.txt > b.list
FINDSTR /s /l /m "cat" *.txt > c.list
FINDSTR /S /L /M /F:a.list rat > a-b.list
FINDSTR /S /L /M /F:b.list hat > a-c.list
FINDSTR /S /L /M /F:c.list cat > b-c.list
Do I need the Quotation marks in the first 3 lines ex) "rat"
Now I have a new set of problems. I made 3 test files, called test1, test2, test3.
In these files I have 1 of the words, 2 of the words, then all three of the words.
This script is finding words such as eduCATion and tHAT. I do not want it to do that. I need this script to find an exact match of 2 or 3 of the words in any combination then tell me which files contain those matches. =/ This is going to require much more work. Any hints or suggestions would be GREATLY appreciated!!
#13
Posted 13 April 2005 - 09:17 AM
If you want to find a string literal, hence " rat " you have to use the /c it works better becuase it allows the use of quites. like this.
C:\>FINDSTR /I /M /S /C:" rat " *.txt > rat.listThis will find all txt files that contain " rat " in them and it should be case insensitive, hence the /i for it Specifies that the search is not to be case-sensitive. Integrate this, and you whould be done.
#14
Posted 13 April 2005 - 12:22 PM
FINDSTR /S /L /M /F:rat.list rat > rat-hat.list
Is that correct?
#15
Posted 13 April 2005 - 12:46 PM
#16
Posted 13 April 2005 - 01:14 PM
FINDSTR /I /M /S /C:" rat " *.txt > rat.list
FINDSTR /I /M /S /C:" hat " *.txt > hat.list
FINDSTR /I /M /S /C:" cat " *.txt > cat.list
Then 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.list
FINDSTR /I /M /S /F:hat.list hat > rat-cat.list
FINDSTR /I /M /S /F:cat.list cat > hat-cat.list
??
#17
Posted 13 April 2005 - 02:09 PM
Quote
should be
FINDSTR /I /M /S /F:rat.list /C:" hat " > rat-hat.list
That way it will search for the literal " hat " in the rat list, and wala you will have a rat-hat list!
#18
Posted 13 April 2005 - 03:09 PM
#19
Posted 13 April 2005 - 03:17 PM
purewaveform, on Apr 13 2005, 09:09 PM, said:
FINDSTR /I /M /S /F:rat.list /C:" hat " > rat-hat.list
That way it will search for the literal " hat " in the rat list, and wala you will have a rat-hat list!
#20
Posted 13 April 2005 - 03:50 PM



Help

Back to top









