I'd like to execute the following awk script (which is working well) in tcl:

exec awk {$1=="text" {print $0}} temp1.txt > temp2.txt}

BUT the problem is that "text" is comming from TK entry widget and I have to put it in a variable ($var) which is not recognized by awk:

set var [.entry get]
exec awk {$1==$var {print $0}} temp1.txt > temp2.txt}

Any idea how to skip it or make it running?

PS I'd like to stay with awk, not to change the code on tcl if it's possible.

Regards, lucas

有帮助吗?

解决方案

Use -v switch in awk to pass external variable to awk:

exec awk -v var=$var {$1==var {print $0}} temp1.txt > temp2.txt}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top