Hi,
The title speaks for itself really. I only want to know if it exists, not where it is. Is there a one liner to achieve this?
Regards,
Chris
Hi,
The title speaks for itself really. I only want to know if it exists, not where it is. Is there a one liner to achieve this?
Regards,
Chris
grep for foo OR bar OR baz, stolen from ruby1line.txt.
$ ruby -pe 'next unless $_ =~ /(foo|bar|baz)/' < file.txt
Well it seems eed3si9n has the one liner down, here's the longer solution:
f = File.new("file.txt")
text = f.read
if text =~ /string/ then
#relevant code
end
Cheatng a little by using a system call:
system("grep meow cat_sounds.txt")
Will return true if grep returns anything, false if it does not.
I find this is the "best" way because Ruby is slow when it comes to file operations.