Reputation: 193
when I run command
awk '/^proc/ {print $2}' <file_name>
in bash I have no problem. But when I use it in Tcl
script using exec
function as
exec awk "/^proc/ {print $2}" win_test.tcl
,
I recevie error can't read "2": no such variable
Upvotes: 1
Views: 64
Reputation: 16428
Enclose the awk
command without single quotes and then use exec
.
set awkCmd {/^proc/ {print $2}}
exec awk $awkCmd <file-name>
Example
[dinesh@mypc mypgms]$ cat sample.tcl
proc Hello {} {
}
proc World {} {
}
[dinesh@mypc mypgms]$ tclsh
% set awkCmd {/^proc/ {print $2}}
/^proc/ {print $2}
% exec awk $awkCmd sample.tcl
Hello
World
%
Upvotes: 3