Count bytes
file = File.new("myfile") e_count = 0 file.each_byte do |byte| e_count += 1 if byte == ?e end