If your input file is not already a standard text file then trying to read it from Procomm may produced a lot of control characters within the text and you may not get the desired results. I do not know if Procomm has any means of converting other format files(ie.*.pdf;*.doc;*.rtf) to text files so you will need some other medium to do this.
As for extracting and manipulating the existing data in either the output or input files, you need to understand what the posted script is doing. The script already opens the output and input files as text.
Code:
fopen 1 OutputFile readwrite text ; Open Output as File ID 1
fopen 2 InputFile read text ; Open Input as File ID 2
While not at the end of the output file,
extract line from each file stored as string var Source.
Code:
fgets 1 Source ; Extract Line from Output File ID 1
fgets 2 Source ; Extract Line from Input File ID 2
At this point, if you are not at the end of the document, the file pointer will be at the begining of the next line. To append the previous line, we need to move the file pointer 2 bytes back to allow for the C/R.
Code:
fseek 1 (-2) 1 ; Set pointer of File ID 1 back 2 bytes
Then, depending of the contents of the Output string
Code:
if strcmp Source GoodString
elseif strcmp Source BadString
We insert a block of space the same size as the string of information we want to insert
Code:
finsblock 1 15 ; Insert 15 Bytes of space into File ID 1
then we insert the sting.
Code:
fwrite 1 ":OK:TUPLE ADDED" 15 ; Write 15 Bytes to File ID 1
After inserting the data, we need to move the file pointer 2 bytes forward to place us back at the begining of the next line.
Code:
fseek 1 2 1 ; Set pointer of File ID 1 forward 2 bytes
before extracting the next lines of data.
Currently, the script does not do anything to the line it extracts from the output file. It only extract a line from the file to ensure file pointer is on the same line in both files. The line extracted from the input file uses
strcmp to see if exactly matches the specified criteria.
Code:
if strcmp Source GoodString
elseif strcmp Source BadString
You could use
strfind instead of strcmp to search for the existence of a string in the extracted line.
Code:
if strfind Source GoodString
or to find the position of GoodString in Source
Code:
strfind Source GoodString StrPos
You could use
substr to extract specified number of characters from a string.
Code:
substr Target Source 0 10 ; Extract first 10 chars of Source to Target
To delete a string from a file, you can use
strlen to determine the length of the string
Code:
strlen Source SrcLen ; Length of Source stored to int Srclen
and then
fdelblock to delete the string.
Code:
fdelblock 1 SrcLen ; Delete SrcLen Bytes from File ID 1
NOTE: You will need to make sure the file pointer is at the begining of the string you want to delete before running fdelblock.
Code:
fseek 1 (-10) 1 ; Set pointer of File ID 1 back 10 bytes