Join all text files in a folder, with a single line of Ruby code

Hi,

At Mon, 27 Oct 2008 16:10:31 +0900,
Peña, Botp [email protected] wrote in [ruby-talk:318654]:

i just tried that nobu, but it gives no output

:~$ ruby -ep *.txt

You needs -p option.

ruby -pep *.txt

Hi,

At Mon, 27 Oct 2008 19:22:57 +0900,
Peña, Botp [email protected] wrote in [ruby-talk:318662]:

> i just tried that nobu, but it gives no output

>

> :~$ ruby -ep *.txt

You needs -p option.

ruby -pep *.txt

you’re saying -ep is different from -e -p ?
i’m asking since i do not see it ruby -h

Each -e needs a following expression, so ‘p’ after it is
Kernel#p, however, -p doesn’t take arguments so ‘e’ after it is
-e.

From: Nobuyoshi N. [mailto:[email protected]]

At Mon, 27 Oct 2008 16:10:31 +0900,

Peña, Botp [email protected] wrote in [ruby-talk:318654]:

> i just tried that nobu, but it gives no output

>

> :~$ ruby -ep *.txt

You needs -p option.

ruby -pep *.txt

you’re saying -ep is different from -e -p ?
i’m asking since i do not see it ruby -h

thanks for the info -botp

Thanks for all replies. A lot of interesting solutions!

www.twitter.com/luisbebop

On Sun, 26 Oct 2008, Robert K. wrote:

File.open(“mrg”,“w”){|f|f.puts Dir[’*.txt’].map{|nm|IO.read nm}}

That’s vastly inefficient since it reads all the files into memory before
writing a single byte. This is not necessary. You can at least improve to

File.open(“mrg”,“w”){|f|Dir[’*.txt’].each{|nm|f.write(File.read(nm))}}

If we’re into fast and ugly…

We need a Ruby interface to Linux “splice”…

splice() moves data between two file descriptors without
copying
between kernel address space and user address space. It
transfers up
to len bytes of data from the file descriptor fd_in to
the file
descriptor fd_out, where one of the descriptors must refer to a
pipe.

See “man splice” for more.

John C. Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : [email protected]
New Zealand

on Mon, Oct 27, 2008 at 8:17 PM, Nobuyoshi N. [email protected]
wrote:

Each -e needs a following expression, so ‘p’ after it is
Kernel#p, however, -p doesn’t take arguments so ‘e’ after it is -e.

dumb me. all the time i thought the quotes were required for -e and
that a space should separate it fr the expression :))
so now even “ruby -pe0 *.txt” should work!

many thanks for the englightenment, nobu.
kind regards -botp