[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

merging files with CR as EOL ?

pere.noel

10/18/2006 9:38:00 AM

i have to rewrite a script in order to be compatible with file lines
ending by CR instead of unix \n

my script is simple, it take the content of a folder and merge the file
all together in a unique file, those files have CR lines ending and such
must be the merged file.

what to do in that case ?
4 Answers

Robert Klemme

10/18/2006 9:41:00 AM

0

On 18.10.2006 11:37, Une Bévue wrote:
> i have to rewrite a script in order to be compatible with file lines
> ending by CR instead of unix \n
>
> my script is simple, it take the content of a folder and merge the file
> all together in a unique file, those files have CR lines ending and such
> must be the merged file.
>
> what to do in that case ?

You could do something like

# untested
File.open("result.txt", "wb") do |out|
Dir["*"].each do |file|
File.open(file) do |in|
in.each_line do |line|
line.chomp!
out.write(line)
out.write("\r\n")
end
end
end
end

Kind regards

robert

Xavier Noria

10/18/2006 9:52:00 AM

0

On Oct 18, 2006, at 11:40 AM, Une Bévue wrote:

> i have to rewrite a script in order to be compatible with file lines
> ending by CR instead of unix \n
>
> my script is simple, it take the content of a folder and merge the
> file
> all together in a unique file, those files have CR lines ending and
> such
> must be the merged file.

If you need to work line-by-line instad of slurping them (which would
be easier and line-ending agnostic), then pass CR as the optional
separator to your line-oriented idiom. For example

cr_text_file.each("\015") do |cr_line|
# ...
end

-- fxn




pere.noel

10/18/2006 1:36:00 PM

0

Robert Klemme <shortcutter@googlemail.com> wrote:

> File.open("result.txt", "wb") do |out|
> Dir["*"].each do |file|
> File.open(file) do |in|
> in.each_line do |line|
> line.chomp!
> out.write(line)
> out.write("\r\n")
> end
> end
> end
> end

yes right because within ruby the chomp is aware of the kind of line
feed is there !

thanks !

harry k

9/14/2010 1:38:00 PM

0

On Sep 14, 12:45 am, BDK <TopSh...@sanity.com> wrote:
> In article <d3d996c8-cf6d-4380-b82c-feeb490cd475
> @j30g2000vbr.googlegroups.com>, xeton2...@yahoo.com says...
>
> > On Sep 12, 12:37 am, Siobhan Medeiros <sbm2...@telus.net> wrote:
>
> > > Gee, a bunch of kooktards get together and claim evidence exists for
> > > their kookery?  What a surprise!
>
> > The board notes that all you govt shills have is namecalling. It must
> > really suck to be a hater.
>
> Do you claim all sane people are "haters", Speedy?
>
> Or just the ones who roll their eyes and laugh at you?
> --
> BDK, non-jew leader of the non-existant paid jew shills!

Errmmm....isn't that _everyone_?

Harry K