Skip to content

Instantly share code, notes, and snippets.

@ckoparkar
Created August 18, 2015 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckoparkar/cd410ab4a3e45351146e to your computer and use it in GitHub Desktop.
Save ckoparkar/cd410ab4a3e45351146e to your computer and use it in GitHub Desktop.
require 'tempfile'
require 'fileutils'
ARGV.each do |name|
temp_file = Tempfile.new('foo')
begin
File.open(name, 'r') do |file|
file.each_line do |l|
s = l.scan(/[\(\/](\[.*?\])/).flatten
s.each {|i| l = l.gsub(i, " #{i} ")}
temp_file.puts l
end
end
temp_file.close
FileUtils.mv(temp_file.path, name)
ensure
temp_file.close
temp_file.unlink
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment