سؤال

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