#!/usr/bin/ruby # for all files file_names = Dir.glob("**/*.h") + Dir.glob("**/*.cpp") new_header = File.read('new_header') old_header = File.read('old_header') file_names.each do |file_name| text = File.read(file_name) new_contents = text.gsub(old_header, new_header) # To merely print the contents of the file, use: #puts new_contents # To write changes to the file, use: File.open(file_name, "w") {|file| file.puts new_contents } end