質問

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