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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Non_ascii Characters

Status
Not open for further replies.

RF101

Technical User
May 17, 2006
33
US


As you can see from my recent posts I am new to Expect

I have everything working close to the way I want it now for my data collection. I just a have a couple small issues.

1. The script below adds a non-ascii character to the end of the file name. Is there a better way to do this?

set tdate [clock format [clock seconds] -format %Y%m%d]
set newName ofcvar_
append newName $tdate
append newName ".txt"

result = ofcvar_20080820.txt(non-ascii junk)

2. The telnet session that I am recording has non-ascii characters in the output file. Is ther a way to remove these from the file. I have a sed script that I have used to remove them but I was wondering if there is way to spawn the telnet session that would not record the non-ascii.


TIA,

RF101
 
First of all $newName should not have any characters (ASCII or non-ASCII) apart from the 19 you put there. You can satisfy yourself on this point:
Code:
set tdate [clock format [clock seconds] -format %Y%m%d]
set newName ofcvar_
append newName $tdate
append newName ".txt"
[b]puts [string length $newName][/b]

I think by "non ascii" you really mean "non-printable"? Anyway, you can remove anything you want from a string with regsub. The code for an alphanumeric (including "_" but not ".") is "\w". So to get rid of anything except alphanumerics and ".", you would do:
regsub -all {[^\w\.]} $newName "" newName

_________________
Bob Rashkin
 
Does anyone know the way to call this from withing Expect?

Expect seems to choke on the ^w\. and does not continue.

I have tried set content [regsub -all {[^\w\.]} $newName "" newName ] but this does not work either.

Thanks,

JB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top