Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > merging files with CR as EOL ?

Reply
Thread Tools

merging files with CR as EOL ?

 
 
Une Bévue
Guest
Posts: n/a
 
      10-18-2006
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 ?
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      10-18-2006
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
 
Reply With Quote
 
 
 
 
Xavier Noria
Guest
Posts: n/a
 
      10-18-2006
On Oct 18, 2006, at 11:40 AM, Une B=E9vue 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 =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




 
Reply With Quote
 
Une Bévue
Guest
Posts: n/a
 
      10-18-2006
Robert Klemme <(E-Mail Removed)> 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 !
 
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
Eclipse: Stripping whitespace at EOL Tim Tyler Java 7 09-15-2011 04:07 PM
Reading text files where last line has no EOL BlueBird Python 4 09-17-2007 07:20 PM
replacing EOL with <br> Daves ASP .Net 1 04-13-2005 11:40 PM
3640 EOL Bill F Cisco 3 11-28-2003 08:27 PM
3640 EOL Issues Bill F Cisco 0 11-27-2003 11:39 PM



Advertisments