I need to create a file if a string exists in Windows
I have a text file example below.
I need a vbs or some other small script to read the file. If the following string appears :
"R ASAP" or "R ASAP"
If either of those two strings appear, then i would like a file to be created in c:\STAT. it can be a simple file called STATEXISTS.txt. Then, i would run another process to react in a certain way if that STATEXISTS.txt file actually does exist.
So, that is all. Just to watch for two strings and if either of them show up in the file, a new file will be created. I have other processes ready, just need this peice of the puzzle resolved before I can move on. THANKS
M F 82 3/17/2009 16:27 CRW CHEST,2-VIEW;PA+LATERAL R ASAP ER PrD
M F 82 3/17/2009 18:20 CTW CHEST ANGIO R ASAP ER PrD
M F 84 12/20/2010 13:31 CTW HEAD WO R ASAP Emergen ER PrD
F 84 12/21/2010 19:38 CTW HEAD WO R ASAP Emergen ER PrD
F 19 1/12/2011 20:51 CRW CHEST,2-VIEW;PA+LATERAL R ASAP Emergen ER PrD
F 49 5/18/2011 05:39 CRW CHEST PORTABLE,1-VIEW R ASAP Inpatient ICU ApD
F 46 4/28/2006 09:35 US UPPER EXT VENOUS UNI/RT R
M 56 7/24/2006 16:18 CT FACIAL MAXILLOFACIAL AREA R
F 47 12/27/2006 10:40 US THRYOID R
M F 80 1/19/2007 17:33 CRW CHEST,2-VIEW;PA+LATERAL R ER
M F 80 5/10/2007 10:41 CAD CAD W/SCREENING R 9D
M F 80 5/10/2007 10:41 MG SCREEN;DIGITAL BILT R 9D
M F 81 12/30/2007 13:05 CRW CHEST,2-VIEW;PA+LATERAL R ER PrD
M F 82 10/27/2008 09:06 MG SCREEN, DIGITAL; BI R 9D PrD
M F 83 4/13/2010 12:24 CRW KNEE,3-VIEW;RGT R OUTPATI RA PrD
M F 83 5/27/2010 10:37 MG SCREEN, DIGITAL; BI R OBSERV 9E PrD
F 53 8/10/2010 14:45 MRI SPINE;LUMBAR R
M F 84 1/11/2011 18:22 CRW HAND,3-VIEW MIN;LFT R Emergen ER PrD
M F 84 1/11/2011 18:26 CRW CHEST,2-VIEW;PA+LATERAL R Emergen ER PrD
F 19 2/02/2011 08:12 CTI SINUS SCREENING R Outpatie IM PrD
@echo off
del c:\stat\statexists.txt 2>NUL
findstr " R*ASAP " yourfile.txt && echo It exists - found in yourfile.txt at %date% %time%> c:\stat\statexists.txt
Specifically that is looking for the string spac, then R, then any number of chars then ASAP then a space which I imagine will do what you are after. We can be more specific if needed.
If the string is found then the command after the && is run, which in this case is creating a file called statexists.txt with the word It exists in.
The del command first makes sure that the file doesn't exist first.
I think was where Steve was headed, you need the /R switch to invoke regular expression mode. And you may want to tweak the filter, right now it requires a space before and after, as well as at least one space in the middle. I also suppressed the output of the matching lines since you probably don't want to see them. If you want to ignore case (right now only caps match) then add the /I switch as well.
@echo offdel c:\stat\statexists.txt 2>NULfindstr /R " R [ ]*ASAP " yourfile.txt && echo It exists - found in yourfile.txt at %date% %time%> c:\stat\statexists.txt
For what it's worth, I think the following is the correct and needed syntax:
findstr /R /C:" R [ ]*ASAP "
If you don't do the /C then I believe FINDSTR "or"s together the substrings in the quoted literal. For example if I do FINDSTR /R "this that" it will find lines that have EITHER this or that in them. Not what we want. Below is a small set of tests on the supplied input, notice the last one is the one that gives what we want.
[Fri 09/16/2011 7:33:17.53 c:\ee]findstr " R[ - ]*ASAP " EE27311064.txtM F 82 3/17/2009 16:27 CRW CHEST,2-VIEW;PA+LATERAL R ASAP ER PrDF 19 1/12/2011 20:51 CRW CHEST,2-VIEW;PA+LATERAL R ASAP Emergen ER PrDF 49 5/18/2011 05:39 CRW CHEST PORTABLE,1-VIEW R ASAP Inpatient ICU ApDM F 80 1/19/2007 17:33 CRW CHEST,2-VIEW;PA+LATERAL R ERM F 81 12/30/2007 13:05 CRW CHEST,2-VIEW;PA+LATERAL R ER PrDM F 83 4/13/2010 12:24 CRW KNEE,3-VIEW;RGT R OUTPATI RA PrDM F 84 1/11/2011 18:22 CRW HAND,3-VIEW MIN;LFT R Emergen ER PrDM F 84 1/11/2011 18:26 CRW CHEST,2-VIEW;PA+LATERAL R Emergen ER PrD[Fri 09/16/2011 7:33:36.52 c:\ee]findstr /R " R [ ]*ASAP " EE27311064.txtM F 82 3/17/2009 16:27 CRW CHEST,2-VIEW;PA+LATERAL R ASAP ER PrD M F 82 3/17/2009 18:20 CTW CHEST ANGIO R ASAP ER PrDM F 84 12/20/2010 13:31 CTW HEAD WO R ASAP Emergen ER PrDF 84 12/21/2010 19:38 CTW HEAD WO R ASAP Emergen ER PrDF 19 1/12/2011 20:51 CRW CHEST,2-VIEW;PA+LATERAL R ASAP Emergen ER PrDF 49 5/18/2011 05:39 CRW CHEST PORTABLE,1-VIEW R ASAP Inpatient ICU ApDF 46 4/28/2006 09:35 US UPPER EXT VENOUS UNI/RT RM 56 7/24/2006 16:18 CT FACIAL MAXILLOFACIAL AREA RF 47 12/27/2006 10:40 US THRYOID RM F 80 1/19/2007 17:33 CRW CHEST,2-VIEW;PA+LATERAL R ERM F 80 5/10/2007 10:41 CAD CAD W/SCREENING R 9DM F 80 5/10/2007 10:41 MG SCREEN;DIGITAL BILT R 9DM F 81 12/30/2007 13:05 CRW CHEST,2-VIEW;PA+LATERAL R ER PrDM F 82 10/27/2008 09:06 MG SCREEN, DIGITAL; BI R 9D PrDM F 83 4/13/2010 12:24 CRW KNEE,3-VIEW;RGT R OUTPATI RA PrDM F 83 5/27/2010 10:37 MG SCREEN, DIGITAL; BI R OBSERV 9E PrDF 53 8/10/2010 14:45 MRI SPINE;LUMBAR RM F 84 1/11/2011 18:22 CRW HAND,3-VIEW MIN;LFT R Emergen ER PrDM F 84 1/11/2011 18:26 CRW CHEST,2-VIEW;PA+LATERAL R Emergen ER PrD F 19 2/02/2011 08:12 CTI SINUS SCREENING R Outpatie IM PrD[Fri 09/16/2011 7:34:05.67 c:\ee]findstr /R /C:" R [ ]*ASAP " EE27311064.txtM F 82 3/17/2009 16:27 CRW CHEST,2-VIEW;PA+LATERAL R ASAP ER PrD M F 82 3/17/2009 18:20 CTW CHEST ANGIO R ASAP ER PrDM F 84 12/20/2010 13:31 CTW HEAD WO R ASAP Emergen ER PrDF 84 12/21/2010 19:38 CTW HEAD WO R ASAP Emergen ER PrDF 19 1/12/2011 20:51 CRW CHEST,2-VIEW;PA+LATERAL R ASAP Emergen ER PrDF 49 5/18/2011 05:39 CRW CHEST PORTABLE,1-VIEW R ASAP Inpatient ICU ApD
================== " R[ - ]*ASAP "M F 82 3/17/2009 16:27 CRW CHEST,2-VIEW;PA+LATERAL R ASAP ER PrD F 19 1/12/2011 20:51 CRW CHEST,2-VIEW;PA+LATERAL R ASAP Emergen ER PrD F 49 5/18/2011 05:39 CRW CHEST PORTABLE,1-VIEW R ASAP Inpatient ICU ApD M F 80 1/19/2007 17:33 CRW CHEST,2-VIEW;PA+LATERAL R ER ================== /R /C:" R [ ]*ASAP "M F 82 3/17/2009 16:27 CRW CHEST,2-VIEW;PA+LATERAL R ASAP ER PrD F 84 12/21/2010 19:38 CTW HEAD WO R ASAP Emergen ER PrD F 19 1/12/2011 20:51 CRW CHEST,2-VIEW;PA+LATERAL R ASAP Emergen ER PrD F 49 5/18/2011 05:39 CRW CHEST PORTABLE,1-VIEW R ASAP Inpatient ICU ApD ================== /R " R [ ]*ASAP "M F 82 3/17/2009 16:27 CRW CHEST,2-VIEW;PA+LATERAL R ASAP ER PrD M F 82 3/17/2009 18:20 CTW CHEST ANGIO R NOT ASAP ER PrD M F 84 12/20/2010 13:31 CTW HEAD WO R XX ASAP Emergen ER PrD F 84 12/21/2010 19:38 CTW HEAD WO R ASAP Emergen ER PrD F 19 1/12/2011 20:51 CRW CHEST,2-VIEW;PA+LATERAL R ASAP Emergen ER PrD F 49 5/18/2011 05:39 CRW CHEST PORTABLE,1-VIEW R ASAP Inpatient ICU ApD F 46 4/28/2006 09:35 US UPPER EXT VENOUS UNI/RT R M 56 7/24/2006 16:18 CT FACIAL MAXILLOFACIAL AREA R F 47 12/27/2006 10:40 US THRYOID R M F 80 1/19/2007 17:33 CRW CHEST,2-VIEW;PA+LATERAL R ER M F 80 5/10/2007 10:41 CAD CAD W/SCREENING R 9D ================== " R*ASAP "M F 82 3/17/2009 16:27 CRW CHEST,2-VIEW;PA+LATERAL R ASAP ER PrD M F 82 3/17/2009 18:20 CTW CHEST ANGIO R NOT ASAP ER PrD M F 84 12/20/2010 13:31 CTW HEAD WO R XX ASAP Emergen ER PrD F 84 12/21/2010 19:38 CTW HEAD WO R ASAP Emergen ER PrD F 19 1/12/2011 20:51 CRW CHEST,2-VIEW;PA+LATERAL R ASAP Emergen ER PrD F 49 5/18/2011 05:39 CRW CHEST PORTABLE,1-VIEW R ASAP Inpatient ICU ApD ================== /R:" R[ - ]*ASAP "M F 82 3/17/2009 16:27 CRW CHEST,2-VIEW;PA+LATERAL R ASAP ER PrD F 84 12/21/2010 19:38 CTW HEAD WO R ASAP Emergen ER PrD F 19 1/12/2011 20:51 CRW CHEST,2-VIEW;PA+LATERAL R ASAP Emergen ER PrD F 49 5/18/2011 05:39 CRW CHEST PORTABLE,1-VIEW R ASAP Inpatient ICU ApD ==================
@echo off
del c:\stat\statexists.txt 2>NUL
findstr " R*ASAP " yourfile.txt && echo It exists - found in yourfile.txt at %date% %time%> c:\stat\statexists.txt
Specifically that is looking for the string spac, then R, then any number of chars then ASAP then a space which I imagine will do what you are after. We can be more specific if needed.
If the string is found then the command after the && is run, which in this case is creating a file called statexists.txt with the word It exists in.
The del command first makes sure that the file doesn't exist first.
Steve