look(1)
Display lines beginning with a given string, using binary search on a sorted file.
Synopsis
look [OPTION]... STRING [FILE]...Description
The look command searches for lines in a file that begin with the specified STRING, using a fast binary search algorithm. This requires the input file to be sorted. If no file is specified, it defaults to /usr/share/dict/words on most systems.
Useful for dictionary lookups, word games, and searching presorted data files much faster than grep. The binary search makes it efficient even on very large files.
Common options
| Flag | What it does |
|---|---|
-a | Use alternate dictionary file (system-dependent) |
-d | Dictionary character set only: ignore non-alphanumeric characters |
-f | Fold: ignore case distinctions (treat uppercase and lowercase as equivalent) |
-t TERMCHAR | Specify a terminate character; search only up to that character in each line |
Examples
Find all words in the system dictionary starting with 'hello'
look helloCase-insensitive search for words beginning with 'hello' in the dictionary
look -f hello /usr/share/dict/wordsShow first 10 words in dictionary starting with 'pre'
look pre /usr/share/dict/words | head -10Search for words starting with 'ab', ignoring non-alphanumeric characters
look -d ab /usr/share/dict/wordsSearch for lines beginning with 'testing' in a custom sorted file
look testing sorted_list.txtCase-insensitive lookup of 'test', 'Test', 'TEST', etc.
look -f Test /usr/share/dict/words