Posted to tcl by mjanssen at Thu Oct 25 00:37:15 GMT 2007view pretty
set re {^$} fconfigure stdout -encoding binary -translation binary -buffering full proc filter {argv re} { foreach file $argv { set f [open $file r] fconfigure $f -encoding binary -translation binary -buffersize 8096 set buffer "" while {![eof $f]} { while {[string first \n $buffer] == -1} { append buffer [read $f 8096] } set bl [split $buffer \n] foreach line [lrange $bl 0 end-1] { if {[regexp -- $re $line]} {puts $line} } set buffer [lindex $bl end] } close $f } } filter $argv $re
Comments
Posted by willdye at Fri Oct 26 21:23:59 GMT 2007 [text] [code]
mcvoy noted on the Tcl Chat that this script is currently 3.6 times slower than the roughly equivalent Perl script: $re='^$'; while(<>){ print if /$re/0;}