i am getting problem in using AWK command in TCK/TK unix command:
var=`awk -v var1="^$line" -F "|" '$1~var1{print $1 }' sort-address-name-ip.txt | awk -v var2="$line$" '$0~var2'`
and i used as:
set var5 [exec /usr/bin/awk -v var1={^$line} -F {|} {$1~var1{print $1 }} sort-address-name-ip.txt | /usr/bin/awk -v var2={$line$} {$0~var2}]
my script:
#!/usr/bin/expect
set file [ open /home/gcngov/script/practice/tcl/policy-unique_single_line-src-dst-ip.txt]
while {[gets $file line] != -1} {
puts $line
set file1 [open /home/gcngov/script/practice/tcl/sort-address-name-ip.txt]
set var5 [exec /usr/bin/awk -v var1={^$line} -F {|} {$1~var1{print $1 }} sort-address-name-ip.txt | /usr/bin/awk -v var2={$line$} {$0~var2}]
puts $var5
}
close $file
output:
~/script/practice/tcl$ expect -d while-file.sh
expect version 5.45
argv[0] = expect argv[1] = -d argv[2] = while-file.sh
set argc 0
set argv0 "while-file.sh"
set argv ""
executing commands from command file while-file.sh
10.13.210.212
missing close-bracket
while executing
"set var5 ["
("while" body line 5)
invoked from within
"while {[gets $file line] != -1} {
puts $line
#set var [exec /usr/bin/awk -v var1="^$line" -F "|" $1~var1{print $1 } sort-address-name-ip.txt | awk..."
(file "while-file.sh" line 3)
]
at the end of the line startingset var5
.Expect.pm
module instead of expect+sh+awk. All of the features of perl (a superset of awk and sed and sh and lots more) plus expect. in one scripting language, No need to shell out to an external program or mess around with argument quoting.exec
in there. That should look likeset var5 [exec awk ... | awk ...]
ie noexec
after the pipe|
. You should check theexec(3tcl)
manpage. Also, all that could be done intcl
-- no need for external commands.