Merging files with CR as EOL?

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 ?

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

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

Robert K. [email protected] wrote:

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

thanks !