Is there anyway to check if a value exist in a file without ALWAYS going through entire file ?
Currently I used:
if open('file.txt').grep(/value/).length > 0
puts "match"
else
puts "no match"
end
But it’s not efficient as I only want to know whether it exists or not. Really appreciate a solution with grep / others similar one-liner.
Please note the “ALWAYS” before down-vote my question
If you want line-by-line comparison using a one-liner: