Home > ruby > Using ruby to fix line endings

Using ruby to fix line endings

I just f*@&ed up my svn entries file by changing the line endings during a manual edit (note: don’t try that at home). But anyways the fix was to load the file in binary mode, strip the spurious line endings and re-write the file in binary mode

e = []; File.open('entries', 'rb') {|f| e = f.read }
File.open('entries', 'wb') {|f| f.write(e.gsub(/\x0D\x0A/, "\x0A") }

Categories: ruby Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.