'Is there a TCL cmd to grep a particular line and awk a particular word
Lets say below is something i've stored in a config variable in tcl.
#set config "configuration {
test_config {
address 1.2.3.4:https
}
}"
Using tcl cmd, either grep or awk or string cmds, how do i take out "1.2.3.4:https" into a variable.
So when i use do something like below,
#puts $output
1.2.3.4:https
I know how it can be done in simple bash though
#echo $config | grep address | awk '{print $2}'
#1.2.3.4:https
Can someone please help in tcl. I tried to explore string functions, but they are not giving my required output and I'm learning about regexp now.
Solution 1:[1]
I'm sure Donal's suggestion is the more efficient: here's a procedural way to do it:
foreach line [split $config \n] {
lassign [regexp -inline -all {\S+} $line] first second
if {$first eq "address"} {
set output $second
break
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | glenn jackman |
