#!/usr/bin/ruby -w if ARGV.size != 2 puts "#{$0} {input.txt} {template.txt} > {output.txt}" exit 1 end # Load non-whitespace characters from input. input = [] File.open(ARGV[0], "r") {|f| f.each_char{|c| if c.match?(/\S/) input += [c] end } } # Copy input characters to non-whitespace characters in template. cursor = 0 File.open(ARGV[1], "r") {|f| f.each_char{|c| if c.match?(/\s/) print c else if cursor >= input.size # Template longer than input. exit end print input[cursor] cursor += 1 end } }