I have a large file containing one string on each line. I would like to be able to quickly determine if a string is in the file. Ideally, this would be done using a binary chop type algorithm.
Some Googling revealed the look
command with the -b
flag which promises to locate and output all strings beginning with a given prefix using a binary search algorithm. Unfortunately, it doesn't seem to work correctly and returns null results for strings that I know are in the file (they are properly returned by the equivalent grep
search).
Does anyone know of another utility or strategy to search this file efficiently?
Best Answer
There's an essential difference between
grep
andlook
:Unless explicitly stated otherwise,
grep
will find patterns even somewhere within the lines. Forlook
the manpage states:I'm not using
look
very often, but it did work fine on a trivial example I just tried.