I have a file with .gz extension. When I try to read and print the file with following TCL commands I can't read the file even though I am able to see the contents in the VI editor.
I tried with the following TCL code:
set of [glob *.gz ]
set op [open "$of" r]
set file_data [read $op]
set data [split $file_data "\n"]
foreach line $data {
puts " $line"
}
In Tcl 8.6, you have built-in support for this so you can do:
set f [open $filename]
zlib push gunzip $f
set data [read $f]
close $f
The zlib push gunzip
just attaches a suitable uncompressing transform to the channel.
In 8.5 and before, you're best to read from a pipeline with zcat
or gzcat
(depending on platform details:
set f [open "|gzcat $filename"]
set data [read $f]
close $f
The down-side is that that's nowhere near as portable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With