TCL can read(n) a file directly; this is both more efficient and more portable than forking out to some command.
#!/usr/bin/env expect
proc slurp {file} {
set fh [open $file r]
set ret [read $fh]
close $fh
return $ret
}
set iplist [slurp iplist.txt]
puts -nonewline $iplist
This also (if necessary) allows various open(n) or chan configure options to be specified, for example to set the encoding:
#!/usr/bin/env expect
package require Tcl 8.5
proc slurp {file {enc utf-8}} {
set fh [open $file r]
chan configure $fh -encoding $enc
set ret [read $fh]
close $fh
return $ret
}
set data [slurp [lindex $argv 0] shiftjis]
chan configure stdout -encoding utf-8
puts $data
Which if saved as readfile and given somefile as input:
% file somefile
somefile: DBase 3 data file with memo(s) (1317233283 records)
% xxd somefile
00000000: 8365 8342 8362 834e 838b .e.B.b.N..
% ./readfile somefile
ティックル
%