简体   繁体   中英

wrapping TCL/TK file with AWK command inside

I've created a simple TCL/TK file which contains a button which executes awk command:

#!/usr/bin/env wish
package require Tk
pack [button .b -text "process" -command {exec awk {$1=="aa" {print $0}} ./input.txt > ./temp.txt}]

Using freewrap I made this file executable on Windows (.exe) and when I push the button I have such an error:

Error: couldn't execute "awk": no such file or directory

Is there a way to include/add awk into .exe output file or attach awk libraires to .exe as external file or other way to make awk command recognized without rewriting awk command on TCL code?

Regards

awk {$1=="aa" {print $0}} ./input.txt > ./temp.txt

in Tcl:

set in [open ./input.txt r]
set out [open ./temp.txt w]
while {[gets $in line] != -1} {
    set firstword [lindex [split [string trim $line]] 0]
    # or: regexp {\S+} $line firstword
    if {$firstword eq "aa"} {puts $out $line}
}
close $in
close $out

The awk-code you showed here is quite simple and can easily be rewritten in tcl.

But you want to know a solution without this, so you need to install an awk exe on your computer. One may find an executable here: http://gnuwin32.sourceforge.net/packages/gawk.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM