문제

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