Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search file for a word if found run a BAT file.

Status
Not open for further replies.

n3mel

IS-IT--Management
Jul 24, 2005
11
US
I need some help getting procomm to search the just received file for the type of call it is. There are many call types that need to to be searched and if found run one of 4 different BAT files. I have added the aspect file that I am using now to capture and create 2 differnt files.

proc main
when $CARRIER call check_carrier
while 1
yield
endwhile

endproc
proc check_carrier
set capture overwrite on
capture on
if $CARRIER == 0
capture off
StartProcess ()
endif

endproc

Proc StartProcess

string sLine
; when elapsed 0 40 call quit
;*
;* If WBFC_DATA.TXT Exists, Delete it.
;*

;if isfile "C:\Program files\Symantec\Procomm Plus\Capture\wbfc_data.txt"
; delfile "C:\Data\wbfc_data.txt"
;endif

;* Get Required Data from Capture File and
;* Copy it to NEW WBFC.TXT File.
;*
;* NOTE THAT CAPTURE FILE and DESTINATION MUST BE DIFFERENT !!
;*

fopen 0 "C:\911\wbfc.txt" Read Text ; Source
fopen 1 "C:\911\wbfc_data.txt" Create Text ; Source
while not feof 0
fgets 0 sLine
if strfind sLine "Final Type:"
fputs 1 sLine
endif
if strfind sLine "Loc:"
fputs 1 sLine
endif
if strfind sLine "AKA:"
fputs 1 sLine
endif
endwhile
fclose 0
fclose 1
runfile ()
run "c:\printout"
endproc

proc runfile


string sLine
string sOutput

if fopen 0 "c:/911/wbfc.txt" READ TEXT
while not feof 0
fgets 0 sLine
if strfind sLine "Group:"
strtok sOutput sLine "X," 2
strdelete sOutput 0 1
if fopen 1 "c:/911/output.txt" CREATE TEXT
fputs 1 sOutput
endif
fclose 1
endif
endwhile
endif
fclose 0
; runmap ()

endproc

This works great but now I need it to do more. Here is a copy of the file I need to read for the call types from it is named wbfc_data.txt

Initial Type: NOTIFFC Final Type: NOTIFFC (NOTIFY FIRE CHIEF)
Loc: 1305 W STRASBURG RD ,50 -- STATION 39 ,50 btwn SUGARS BRIDGE RD & NORTHBRO
AKA: Municipality: WBRAD Dev:

See were initial Type: NOTIFFC that is the code word I need to read and then depending on the type code which BAT file will be ran.

Thanks for any help here!

N3MEL








 
If I am understanding correctly, you need to look for one of four possible codes (NOTIFFC being the example above) and that is all. Is that right? If so, is there any reason you can't use strfind to search for the possible four codes in that line and then run the batch file appropriate for each code, like this pseudocode below?

if strfind "code1"
run "code1.bat"
elseif strfind "code2"
run "code2.bat"
elseif strfind "code3"
run "code3.bat"
elseif strfind "code4"
run "code4.bat"
endif

Another option would be to use the strextract command to pull the code from the line (first using strfind to search for the Initial Type: header), assuming that the number of spaces between the header and the code are constant. You could then use a switch/case structure to run the appropriate batch file for each possible code.


 
Knob thanks for responding to my post. There are 4 BAT files but there are 20 or 25 possable type codes so I need to check the type code then run the correct BAT file. I think with your 1st part I can do that but how do I get it to read the wbfc_data.txt file to search for the type code? And should I make it a new script or but it in the one I am using now?
 
OK, if you only have four batch files and over 20 codes, then I think the switch/case will be the way to go since you can specify the same batch file for multiple codes like this:

switch sVar
case "code1"
case "code2"
case "code3"
run "file1.bat"
endcase
case "code4"
case "code5"
run "file2.bat"
endcase
endswitch

I don't see any reason you couldn't use your existing script to check for the values. As for getting the value of the code, you would use strfind as before to locate the line with the Initial Type: string. Then, you would use strextract to pull the fourth string from the line (since it looks like there is a leading space at the beginning like this:

strextract sLine sCode 3

The 3 is because the offset is zero-based. This should pull the NOTIFFC code from the example screenshot you posted.


 
I understand what you showing me but I am not sure I know how to compile it all togetter?
 
Knob I can not get the file opened and the strfind to compile? Not sure what I am doing wrong.
 
Keeps telling me missing tokin

proc main

fopen 0 "C:\911\wbfc_data.txt" Read Text ; Source
while not feof 0
fgets 0
if strfind "Brush"
run "Printout.bat"
elseif strfind "code2"
run "Printout.bat"
elseif strfind "code3"
run "Printout.bat"
elseif strfind "code4"
run "Printout.bat"
endif
endwhile

endproc
 
The fgets command on line 5 needs a string variable to hold the line read from wbfc_data.txt

For the strfind commands, you need to use that string variable between strfind and the string you are looking for like this:

if strfind sVar "Brush"


 
Knob I have no idea why I can not get it to work, keep getting missing token. I do not understand this script very well at all.


 
Ok Knob I got it working I just added them into my sline statement in my script I have been using and it works great!

Thank you very much for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top