$linuxjunkies
>

look(1)

Display lines beginning with a given string, using binary search on a sorted file.

UbuntuDebianFedoraArch

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

FlagWhat it does
-aUse alternate dictionary file (system-dependent)
-dDictionary character set only: ignore non-alphanumeric characters
-fFold: ignore case distinctions (treat uppercase and lowercase as equivalent)
-t TERMCHARSpecify a terminate character; search only up to that character in each line

Examples

Find all words in the system dictionary starting with 'hello'

look hello

Case-insensitive search for words beginning with 'hello' in the dictionary

look -f hello /usr/share/dict/words

Show first 10 words in dictionary starting with 'pre'

look pre /usr/share/dict/words | head -10

Search for words starting with 'ab', ignoring non-alphanumeric characters

look -d ab /usr/share/dict/words

Search for lines beginning with 'testing' in a custom sorted file

look testing sorted_list.txt

Case-insensitive lookup of 'test', 'Test', 'TEST', etc.

look -f Test /usr/share/dict/words

Related commands