Ben Everitt <
[email protected]> wrote:
I'm taking the prompt on devices that's a hostname ending with a colon.
IE: devicename:
I'm grabbing it with expect_out(buffer).
I need to pipe it to sed or regsub to remove the colon and create a new variable that I can reference for file naming.
Just remove colons from the end of the string:
set hostname [string trimright $expect_out(buffer) ":"]
remove all colons - even any in the middle of the string:
set hostname [string map {: ""} $expect_out(buffer)]
do it with regular expressions:
regsub -all -- {:} $expect_out(buffer) {} hostname
regsub can write directly to a variable, therefore no "set ... [...]" here.
Piping to "sed" is among the worst solutions to that task ;-)
After trying all the iterations I can come up with, here's my current progress:
set hostname [$expect_out(buffer) | exec sed {s/://}]
Just for the sake of learning tcl, that would be:
set hostname [exec sed {s/://} << $expect_out(buffer)]
Or to really use a pipe, just to see how that would be syntactically done:
set hostname [exec echo $expect_out(buffer) | sed {s/://}]
But this has some very rough edges, and may lead to dangerous bugs,
if the expect_out(buffer) ever contains certain "nasty" characters
at the start of the string. Just don't do it that way!
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)