Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > unix zcat with ruby?

Reply
Thread Tools

unix zcat with ruby?

 
 
music
Guest
Posts: n/a
 
      04-23-2007
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?
 
Reply With Quote
 
 
 
 
Robert Dober
Guest
Posts: n/a
 
      04-23-2007
On 4/23/07, music <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
music
Guest
Posts: n/a
 
      04-24-2007
Robert Dober wrote:
> On 4/23/07, music <(E-Mail Removed)> 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?
 
Reply With Quote
 
Robert Dober
Guest
Posts: n/a
 
      04-24-2007
On 4/24/07, music <(E-Mail Removed)> wrote:
> Robert Dober wrote:
> > On 4/23/07, music <(E-Mail Removed)> 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

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      04-24-2007
On 24.04.2007 09:04, music wrote:
> Robert Dober wrote:
>> On 4/23/07, music <(E-Mail Removed)> 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
 
Reply With Quote
 
music
Guest
Posts: n/a
 
      04-24-2007
Robert Dober wrote:
> On 4/24/07, music <(E-Mail Removed)> wrote:
>> Robert Dober wrote:
>> > On 4/23/07, music <(E-Mail Removed)> 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?
 
Reply With Quote
 
Robert Dober
Guest
Posts: n/a
 
      04-24-2007
On 4/24/07, music <(E-Mail Removed)> wrote:
> Robert Dober wrote:
> > On 4/24/07, music <(E-Mail Removed)> wrote:
> >> Robert Dober wrote:
> >> > On 4/23/07, music <(E-Mail Removed)> 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/libdo...doc/index.html


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

 
Reply With Quote
 
music
Guest
Posts: n/a
 
      04-24-2007
Robert Dober wrote:
> On 4/24/07, music <(E-Mail Removed)> wrote:
>> Robert Dober wrote:
>> > On 4/24/07, music <(E-Mail Removed)> wrote:
>> >> Robert Dober wrote:
>> >> > On 4/23/07, music <(E-Mail Removed)> 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/libdo...doc/index.html
>


Yes but can I use ARGF with zlib?
 
Reply With Quote
 
music
Guest
Posts: n/a
 
      04-24-2007
music wrote:
> Robert Dober wrote:
>> On 4/24/07, music <(E-Mail Removed)> wrote:
>>> Robert Dober wrote:
>>> > On 4/24/07, music <(E-Mail Removed)> wrote:
>>> >> Robert Dober wrote:
>>> >> > On 4/23/07, music <(E-Mail Removed)> 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/libdo...doc/index.html
>>

>
> 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.
 
Reply With Quote
 
Robert Dober
Guest
Posts: n/a
 
      04-24-2007
On 4/24/07, music <(E-Mail Removed)> wrote:
> music wrote:
> > Robert Dober wrote:
> >> On 4/24/07, music <(E-Mail Removed)> wrote:
> >>> Robert Dober wrote:
> >>> > On 4/24/07, music <(E-Mail Removed)> wrote:
> >>> >> Robert Dober wrote:
> >>> >> > On 4/23/07, music <(E-Mail Removed)> 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/libdo...doc/index.html
> >>

> >
> > 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C Programming 18 01-10-2005 03:35 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C++ 12 01-10-2005 03:35 AM
zcat output Me Perl 1 12-28-2004 05:40 PM
Speed gap between zcat and zlib's GzipReader David G. Andersen Ruby 3 10-26-2004 03:58 AM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-22-2004 10:59 PM



Advertisments