If you want to search for lines that start with a specific string / words, then look command will be useful. (There are other useful Linux command line tools like aspell that can check for typos which are easy to use and quick.)
Also unlike using grep to find instances of specific words, look is used only for finding lines that begin with a specified string or letters.
Using it is simple, open Terminal and type :
look inputstring filename
So for example, from a text file named plants.txt ,to get the lines that start with the word ‘We‘ (which is common in most sentences), the syntax is :
look We plants.txt
This will display all the instances of lines in that file which start with ‘We’.
The look command can also display lines that start with a specific letter instead of a word/string. The syntax is the same as before :
look P plants.txt
This will display all the lines that start with the letter ‘P‘ from the file plants.txt.
Searching in default dictionary:
If no file is specified, look will search for instances in the default dictionary which is at /usr/share/dict/words.
So, say to display a list of words from the user dictionary that start with the string ‘help‘, the command is :
look help
This will show all the possible words that start with that string.
To list words from the user dictionary that start with the string ‘computer‘ :
look computer
There are also a couple of parameters that can be used when using the look command.
Searching for alphanumeric strings :
The -d flag will force it to only look for alphanumeric strings.
look -d 3 Plants.txt
Ignoring uppercase and lowercase :
The look command is case sensitive by default. So, if you want look to search for strings or letters without being case sensitive, use the -f flag.
look -f the plants.txt
In the above example, lines beginning with all instances of the string (The and the) will be searched for and be displayed as the upper and lower case is ignored.
Simple and handy, do try it out.