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!

Expect with a <bell> delimited file

Status
Not open for further replies.

jaytco

Vendor
Dec 13, 2001
88
US
Here is a tricky one. I am using expect to log into another machine via a serial link (only communications available). I generate a report that is saved to a file (It will not send it to stdout). The file is stored with attribute=value(delimiter)attribute=value.... The problem that I have is when trying to parse the file and store the attribute=value into an expect array is that I can not delimite the file. The delimiter is the <bell>. From what I have found it is the hex 07 value or the escape a. As of yet I can not get it to work.
The closest that I got was to generate the file and cat it. Any thoughts would be appreciated.

--Jay
 
If you are coding the whole thing and generating the file
why not change the delimiter?


 
I am coding the whole thing, but the program that I am executing to generate the data set the delimiter. I did find that once the file is generated, I can cat the file and store the cat into a expect_out(buffer) and store that to a file one the local maching, and the bell will turn into a ^F in the buffer, from there I can capture the control char and change it to a ',' like a normal human.
 
If you're able to get the contents of the file in your script, it's easy to edit the string to convert the delimiter character. Based on what you just reported, I'm assuming that you're able to retrieve the contents of the file into expect_out(buffer) or expect_out(0,string). If you're using Tcl 8.1.1 or later, you can use the string map command to translate one or more character sequences into other character sequences. Translating [tt]\x07[/tt] characters into commas would simply be a matter of:

Code:
set result [string map [list \x07 ,] $expect_out(buffer)]

If string map isn't available, you still have a couple of options. One is to perform regular expression-based substitution with the regsub command as follows:

Code:
regsub -all &quot;\x07&quot; $expect_out(buffer) &quot;,&quot; result

And finally, you can use a combination of split and join:

Code:
set result [join [split $expect_out(buffer) &quot;\x07&quot;] &quot;,&quot;]

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
This looks like a great way to do what I need. Thx!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top