E=mc2
asked on
How can I search through a file to check to see if there are two lines that start with the same characters?
At a command line in Windows, I want to search through a specific file and if it finds 2 instances of a line beginning with the same alphacharacters, then it needs to run a a specific vbs script.
For instance, in file located at c:\info\input.txt
Searching through the file,
If there are two lines in succession which start with DTM*, then it needs to run a cscript of 2.vbs, however if it finds
only 1 line starting with DTM* on it's own, then it needs to run 1.vbs.
What command line commands can I use to accomplish this?
Thanks.
For instance, in file located at c:\info\input.txt
Searching through the file,
If there are two lines in succession which start with DTM*, then it needs to run a cscript of 2.vbs, however if it finds
only 1 line starting with DTM* on it's own, then it needs to run 1.vbs.
What command line commands can I use to accomplish this?
Thanks.
ASKER
Thank you. It seems to search through the file well, however how can identify the path where 1.vbs and 2.vbs resides? Currently I have both vbs files in the same folder however the vbs file is not executing.
Do you only want to consider it a double if it is on the very next line, or could it be separated from the first by other lines?
~bp
~bp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
The vbs files are in a different path than the script, how can I modify the cscript to show the correct path where the vbs files reside?
The vbs files are in a different path than the script, how can I modify the cscript to show the correct path where the vbs files reside?
Just set the path in lines 15 (for the 1 line scenario) and 17 (for the 2 lines scenario) after the "cscript.exe /nologo".
Open in new window
Edit: Forgot to ask: do you need to pass the file to analyze as command line argument, or can it remain hardcoded?