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!

Script to take info from Capture and move to new files. 2

Status
Not open for further replies.

chief39

Technical User
Aug 4, 2002
14
US
After capturing info to file I need to look at the file. If a key word is found then a few lines of text will need
to be moved to a new file.There are 3 key words to look for, but there will only be one per capture. It will also be the same lines of text for each key word as well.

Thanks

Glenn

 
Glenn,

That can be done pretty easily. Can you Post an Example capture file and Note what data is needed to be sent to a new Output File ??

hank
 
Looks like the example I posted earlier didn't make it. This shows how to read data line-by-line from autoexec.bat, then check the line for one of two keywords.

proc main
string sLine

fopen 0 "c:\autoexec.bat" READ TEXT
while not feof 0
fgets 0 sLine
if strsearch sLine "temp"
usermsg "temp found!"
endif
if strsearch sLine "path"
usermsg "path found"
endif
endwhile
fclose 0
endproc

After you've read the data in, here's an example of how to write it out to a different file:

fopen 1 "c:\temp.txt" CREATE TEXT
read additional data via fgets command and massage data if necessary.
fputs 1 sLine
fclose 1 aspect@aspectscripting.com
 
Here is the script I am using now Thanks to Knob!! It works great.

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
endif
StartProcess ( )
endproc

Proc StartProcess
string sLine

fopen 0 "C:\Program files\Symantec\Procomm Plus\Capture\wbfc.txt.cap" Read Text ; Source File
set capture overwrite on
fopen 1 "C:\Program files\Symantec\Procomm Plus\Capture\wbfc.txt" Create Text ; Destination File
while not feof 0
fgets 0 sLine
if strfind sLine "Final Type:"
fputs 1 sLine
endif
if strfind sLine "Fire Box:"
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
endproc

Now I need to pull the sline info off as I am doing now but!! Now I need it to save to different files depending on the key words found. Here is a copy of the text info it is the same format every time.

+++


Inc History #WBRF02000598 Xref: #50PJ02000875
TEST ONLY
Received 09/02/02 16:40:24 BY CT01 584
Entered 09/02/02 16:40:54 BY CT01 584
Dispatched 09/02/02 16:41:11 BY XD19 151
Enroute 09/02/02 16:43:00
Onscene 09/02/02 16:52:47

Initial Type:ASEIZUR Final Type: ASEIZUR (SEIZURES - ALS *)
- BLS
*
Initial Priority: 1 Final Priority: 1
Initial Alarm Level: 1 Final Alarm Level: 1 Disposition: Source: 9 Primary Unit: AMB462 Rsp: 0045
Police BOX: 5008 Fire BOX: 3909 EMS BOX: 3909
Group: 39FD Section: 39 Map: X: 7569102 Y: 3997912

Loc: 1111 MARYLAND CI ,50 btwn MARYLAND CI & MARYLAND CI (V)
AKA: Municipality: WBRAD Dev:
Name: TEST ONLY !! Addr: SAA PH: 610-269-6882


/1640 (584 ) ENTRY 21MONTHS/F - SEIZURE
/1641 (151 ) DISP AMB461 #AMB461 AMB461 MDT
/1641 ASST MED932 #MED932 MED932 MDT
/1641 ASST 39QRS
/1641 (584 ) SUPP NAM: MILLER, STEFFANIE,
ADR: SAA,
TXT: MED HX - NO / HAS TAKEN TYLONOL FOR FEVER


/1643 (MED932) *ENROUT MED932
/1644 (436 ) $PREMPT AMB461
/1644 $ASSTER AMB462 #AMB462 AMB462 MDT
/1644 EXCH AMB461 AMB462
/1648 (151 ) ENROUT 39QRS [LT-A]
/1652 (AMB462) *ONSCNE AMB462
/1705 (MED932) *AOR MED932
/1709 (AMB462) *TRANS AMB462 [CCH]
/1710 *MISC AMB462 ,051
/1711 (151 ) AIQ 39QRS


+++

Ok in the line that looks like!

Initial Type:ASEIZUR Final Type: ASEIZUR (SEIZURES - ALS *)

At the end here ( SEIZURES - ALS *)
The -ALS is the key word the other key would be -BLS or just
a *. So if the script sees one of these keys I need a file with the same sline info as I am getting now but only placed in ALS.txt or BLS.txt or fire.txt.

Ok I hope this helps?

Thanks
 
Hello,

If the Data is in a Capture File and you need to save it to a Specific File Name, you might do this.

Proc Main
string sLine
string dFile
Fopen 1 "C:\Files\Data.txt" Read Text
while not feof 1
fgets 1 sLine
if strfind sLine "SEIZURES - ALS *"
dFile = "C:\FILES\ALS.TXT"
endif
if strfind sLine "SEIZURES - BLS *"
dFile = "C:\FILES\ALS.TXT"
endif
endwhile
rewind 1
Fopen 2 dFile Create Text
while not feof 1
fgets 1 sLine
fputs 2 sLine
endwhile
fclose 1
fclose 2
Endproc

Hope this Helps get you going in the right direction.

Hank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top