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!

looping thru a block of text - PBX TNB Rpt

Status
Not open for further replies.

lakehouse

Technical User
May 17, 2004
45
US
I need to read thru a capture file of a Nortel PBX TNB report using strfind. The Terminal Number report represents the features and button programming of each telephone set. Each TN is grouped in a vertical format with a field name, space, and value(s) to the right, carriage return, next field name, etc. I can strfind the feature data where the report is consistant in order of appearance (no problem there).

The problem is the last half of TN rpt containing the phone set key (button) programming has varible lines of text, and the data assigned to Keys are found with no specific pattern/order or may not programmed at all. Thus I believe I must loop thru a block of text several times, each time strfind a different field name and collect the desired data.

I think I need to do the following:
>Identify begining and end of the text block using strfind (" KEY 00 " and " DATE: ")
>Count lines of text between these two markers
>Go back to the start of the block and while tracking line count
>strfind the first field name "CFW" and collect the data; else data = ""
>Go back to start of block marker
>strfind the next field name "SCU", collect data; else data = ""
>Go back...etc. for about 3-4 fields to collect.
>Repeat the feature section and Key programming section for each set TN until EOF is reached.

I haven't found any Aspect examples explaining how to loop thru a portion of the capture file, then move on to the next TN group. This information would be valued for other reports I wish to deseminate into spreadsheets.

Thanks in advance.

 
I think the problem you are really trying to solve is how to go back in the capture file (I assume you are reading it via fgets or a similar command) after you have already read a portion of that file and need to reread that same block. If so, you can use the ftell command to find out where you are in the file (you would want to do this after you have identified the beginning of the block). After you have read through the block and retrieved the first piece of information and need to read the block for the next bit, you could use this command to get back to the previously-saved location in the file:

fseek <file id> <saved value from ftell command> 0


aspect@aspectscripting.com
 
thanks knob,
I like your concept for identifying the beginning of the block with ftell and pointing back to it after I strfind or fgets the data with fseek.

But how do I prevent the search from going beyond the end of the block when the specific data I'm searching for in one pass does not exist in this block? I need some way of detecting the end of the block and point back to the beginning of the block to continue my search passes for the other data fields until the last data search is done.

I do have the text "DATE DD Mmmm YYYY" always appearing on the last line of the block followed by a double line feed that could be tested for.
 
I have a function on my site that acts like strfind, but can search for multiple strings per function call. You could use it to search for both the bit of data you were looking for and the end marker for the block. The script is located here:


Unfortunately as written it doesn't return which string was found, but you could do a quick strfind to determine which of the two strings you were looking for were found. In other words, if you then performed an if strfind for the end of data block, you would want to move on to the next block if the command was successful, or you would know you had the next bit of data you were searching for if the command failed. You should be able to do this in an if strfind/else/endif structure.

I've pasted the discussion of this script from my site as well:

The strfind command only allows you to search for one string within another string. This function accepts a string of data you wish to search, a string containing a variable number of substrings to search for, the delimiter of the substrings string, and the number of substrings you are passing. A 1 is returned if a match was found, otherwise a 0 is the returned result. This function is very extensible as none of the values are hardcoded.


aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top