merging files with CR as EOL ?

U

Une Bévue

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

Robert Klemme

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
 
X

Xavier Noria

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 =20
file
all together in a unique file, those files have CR lines ending and =20=
such
must be the merged file.

If you need to work line-by-line instad of slurping them (which would =20=

be easier and line-ending agnostic), then pass CR as the optional =20
separator to your line-oriented idiom. For example

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

-- fxn
 
U

Une Bévue

Robert Klemme said:
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 !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,215
Messages
2,571,113
Members
47,709
Latest member
Demetrius2

Latest Threads

Top