[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

unix zcat with ruby?

music

4/23/2007 1:39:00 PM

I have to read in many files.
I prefer to concat those files and reading only one large file.
There is a way like unix zcat?
13 Answers

Robert Dober

4/23/2007 2:15:00 PM

0

On 4/23/07, music <music@musi.ca> wrote:
> I have to read in many files.
> I prefer to concat those files and reading only one large file.
> There is a way like unix zcat?
>
>
Sure is
ARGF
HTH
R.

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

music

4/24/2007 7:05:00 AM

0

Robert Dober wrote:
> On 4/23/07, music <music@musi.ca> wrote:
>> I have to read in many files.
>> I prefer to concat those files and reading only one large file.
>> There is a way like unix zcat?
>>
>>
> Sure is
> ARGF

ARGF ok, but how can I pass ARGF to a method?

Robert Dober

4/24/2007 7:30:00 AM

0

On 4/24/07, music <music@musi.ca> wrote:
> Robert Dober wrote:
> > On 4/23/07, music <music@musi.ca> wrote:
> >> I have to read in many files.
> >> I prefer to concat those files and reading only one large file.
> >> There is a way like unix zcat?
> >>
> >>
> > Sure is
> > ARGF
>
> ARGF ok, but how can I pass ARGF to a method?
>
>
As a global constant it is visible anywhere, you can thus simply do
things like this

def my_method
ARGF.each_line do
| line |
whatever
end
end

R.

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Robert Klemme

4/24/2007 7:31:00 AM

0

On 24.04.2007 09:04, music wrote:
> Robert Dober wrote:
>> On 4/23/07, music <music@musi.ca> wrote:
>>> I have to read in many files.
>>> I prefer to concat those files and reading only one large file.
>>> There is a way like unix zcat?
>>>
>>>
>> Sure is
>> ARGF
>
> ARGF ok, but how can I pass ARGF to a method?

What???


some_method(ARGF)

robert

music

4/24/2007 7:41:00 AM

0

Robert Dober wrote:
> On 4/24/07, music <music@musi.ca> wrote:
>> Robert Dober wrote:
>> > On 4/23/07, music <music@musi.ca> wrote:
>> >> I have to read in many files.
>> >> I prefer to concat those files and reading only one large file.
>> >> There is a way like unix zcat?
>> >>
>> >>
>> > Sure is
>> > ARGF
>>
>> ARGF ok, but how can I pass ARGF to a method?
>>
>>
> As a global constant it is visible anywhere, you can thus simply do
> things like this
>
> def my_method
> ARGF.each_line do
> | line |
> whatever
> end
> end

Great!!! and if input files are in gzip format? how can I read them?

Robert Dober

4/24/2007 7:55:00 AM

0

On 4/24/07, music <music@musi.ca> wrote:
> Robert Dober wrote:
> > On 4/24/07, music <music@musi.ca> wrote:
> >> Robert Dober wrote:
> >> > On 4/23/07, music <music@musi.ca> wrote:
> >> >> I have to read in many files.
> >> >> I prefer to concat those files and reading only one large file.
> >> >> There is a way like unix zcat?
> >> >>
> >> >>
> >> > Sure is
> >> > ARGF
> >>
> >> ARGF ok, but how can I pass ARGF to a method?
> >>
> >>
> > As a global constant it is visible anywhere, you can thus simply do
> > things like this
> >
> > def my_method
> > ARGF.each_line do
> > | line |
> > whatever
> > end
> > end
>
> Great!!! and if input files are in gzip format? how can I read them?
>
>
http://www.ruby-doc.org/stdlib/libdoc/zlib/rdoc/...


--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

music

4/24/2007 8:11:00 AM

0

Robert Dober wrote:
> On 4/24/07, music <music@musi.ca> wrote:
>> Robert Dober wrote:
>> > On 4/24/07, music <music@musi.ca> wrote:
>> >> Robert Dober wrote:
>> >> > On 4/23/07, music <music@musi.ca> wrote:
>> >> >> I have to read in many files.
>> >> >> I prefer to concat those files and reading only one large file.
>> >> >> There is a way like unix zcat?
>> >> >>
>> >> >>
>> >> > Sure is
>> >> > ARGF
>> >>
>> >> ARGF ok, but how can I pass ARGF to a method?
>> >>
>> >>
>> > As a global constant it is visible anywhere, you can thus simply do
>> > things like this
>> >
>> > def my_method
>> > ARGF.each_line do
>> > | line |
>> > whatever
>> > end
>> > end
>>
>> Great!!! and if input files are in gzip format? how can I read them?
>>
>>
> http://www.ruby-doc.org/stdlib/libdoc/zlib/rdoc/...
>

Yes but can I use ARGF with zlib?

music

4/24/2007 10:21:00 AM

0

music wrote:
> Robert Dober wrote:
>> On 4/24/07, music <music@musi.ca> wrote:
>>> Robert Dober wrote:
>>> > On 4/24/07, music <music@musi.ca> wrote:
>>> >> Robert Dober wrote:
>>> >> > On 4/23/07, music <music@musi.ca> wrote:
>>> >> >> I have to read in many files.
>>> >> >> I prefer to concat those files and reading only one large file.
>>> >> >> There is a way like unix zcat?
>>> >> >>
>>> >> >>
>>> >> > Sure is
>>> >> > ARGF
>>> >>
>>> >> ARGF ok, but how can I pass ARGF to a method?
>>> >>
>>> >>
>>> > As a global constant it is visible anywhere, you can thus simply do
>>> > things like this
>>> >
>>> > def my_method
>>> > ARGF.each_line do
>>> > | line |
>>> > whatever
>>> > end
>>> > end
>>>
>>> Great!!! and if input files are in gzip format? how can I read them?
>>>
>>>
>> http://www.ruby-doc.org/stdlib/libdoc/zlib/rdoc/...
>>
>
> Yes but can I use ARGF with zlib?

Any help? I'm searching in Zlib::GzipReader class but I can't undestand
how I can use with ARGF.

Robert Dober

4/24/2007 10:40:00 AM

0

On 4/24/07, music <music@musi.ca> wrote:
> music wrote:
> > Robert Dober wrote:
> >> On 4/24/07, music <music@musi.ca> wrote:
> >>> Robert Dober wrote:
> >>> > On 4/24/07, music <music@musi.ca> wrote:
> >>> >> Robert Dober wrote:
> >>> >> > On 4/23/07, music <music@musi.ca> wrote:
> >>> >> >> I have to read in many files.
> >>> >> >> I prefer to concat those files and reading only one large file.
> >>> >> >> There is a way like unix zcat?
> >>> >> >>
> >>> >> >>
> >>> >> > Sure is
> >>> >> > ARGF
> >>> >>
> >>> >> ARGF ok, but how can I pass ARGF to a method?
> >>> >>
> >>> >>
> >>> > As a global constant it is visible anywhere, you can thus simply do
> >>> > things like this
> >>> >
> >>> > def my_method
> >>> > ARGF.each_line do
> >>> > | line |
> >>> > whatever
> >>> > end
> >>> > end
> >>>
> >>> Great!!! and if input files are in gzip format? how can I read them?
> >>>
> >>>
> >> http://www.ruby-doc.org/stdlib/libdoc/zlib/rdoc/...
> >>
> >
> > Yes but can I use ARGF with zlib?
>
> Any help? I'm searching in Zlib::GzipReader class but I can't undestand
> how I can use with ARGF.
>
>
Something like this
ruby -rzlib -e 'reader = Zlib::GzipReader.new(ARGF);reader.each_line
do |x| puts x end' xxx.gz
I discovered however that
Zlib::GzipReader.new(ARGF)
seems to ignore all but the first file in the argument list - unless I
did something stupid - that complicates matters slightly, you still
can do things like

ARGV.each do
| filename |
Zlib::GeipReader.open( filename) do
|gz|
gz.each_line ....
...
end
end

of course but this behavior surprises me a little bit, maybe you
should mine the Zlib doc for this.

Robert

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Robert Dober

4/24/2007 10:53:00 AM

0

>
> of course but this behavior surprises me a little bit,
forget what I said, I just switched my brain on
the concatenation of two gzipped streams is of course not a gzipped stream,
Zlib does well to inflate the first one, maybe a warning would be nice.
R.