Created
April 11, 2010 22:02
-
-
Save moonmaster9000/363103 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# applies a transform_function (Proc instance) to an input_file | |
# and writes it out to the output_file | |
def transform_file(transformer_function, input_file, output_file) | |
File.open(output_file, 'w') do |f| | |
f.write transformer_function.call(File.read(input_file)) | |
end | |
end | |
# returns a proc that splits a newline on either | |
# Windows or Unix-style line endings, then joins | |
# them with Unix-style line endings | |
def unix_newlines | |
lambda {|f| f.split.join("\n")} | |
end | |
if ARGV.length != 2 | |
raise( | |
StandardError, | |
"You must provide two file names on the command line!" | |
) | |
else | |
transform_file unix_newlines, ARGV.first, ARGV.last | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment