# original slow method to find a number plus a divider (|) # at the start of a line def find_num(file, num) found = false File.read(file).each do |line| if line.chomp.split('|', -1)[0] == num found = true break end end # new method that uses the system's grep # since this calls the system, make sure that you trust the values # of file and num def find_num(file, num) found = false found = true if %x[grep -cm1 "^#{num}|" "#{file}"].chomp == '1' found end