[Richard Suchenwirth] -- Here's a tiny script (executable for Unix) that takes 1..3 Tcl scripts (not files - literal code!) as arguments and evaluates * the first (if more than one - may be an empty string) in the beginning * the second (or first if only one) for each line from stdin * the third (if present) in the end: after eof on stdin This is of course modeled after the 'BEGIN{this}{that}END{finally}' pattern of awk scripts, but I didn't want to introduce special keywords. To make it more awk-like, I however introduced special variables FS (field separator), OFS (output field separator), NF (number of fields in current line), NR (number of records - lines - so far), 0 (the whole input line), 1..$NF (fields as split by FS; you get the last field with [[set $NF]]). I use this script for short Tcl tasks that I don't want to write a program file for, e.g. owh '' 'lappend t $0' 'puts [join [lsort -index end -integer -decreasing $t] \n]' to sort output of a pipe the way I want it, but it can be used simply like owh 'puts [string toupper $0]' owh 'set n 0' 'incr n' 'puts $n' 10 break; puts $0' 1} { eval [lindex $argv 0] set _body [lindex $argv 1] ;# strip outer braces set _exit [lindex $argv 2] } else { set _body [lindex $argv 0] ;# strip outer braces set _exit {} } set NR 1 while 1 { gets stdin line if [eof stdin] break awksplit $line $FS eval $_body incr NR } set res [eval $_exit] if [string length $res] {puts $res} ---- Okay Richard, just to prove that I really am on it, here's the current state of perlytcl (gimme a coupla days to finish!): #!/bin/sh # use -*-Tcl-*- \ exec tclsh "$0" "$@" set awk 0 set print 1 set bak {} foreach arg $args { # if we are doing in-place edits, get the bak pattern regexp {^(-[an]*i)\.?(.+)?} $arg -> arg bak switch -exact -- $arg { -an - -na - -a - -n { # default will be to print, so we won't support p if { [ regexp {a} $arg ] } { set awk 1 } if { [ regexp {n} $arg ] } { set print 0 } } -ani - -nai - -i { } -ane - -nae - -e { # script follows! then filenames } default { if { [ string match $switch -e ] } { set cmd $arg set switch {} # sorry, we silently lose non-existent files } elseif { [ file exists $arg ] } { lappend files $arg } } } # end of switch } foreach file $files { }