Contact Managers
Pages: 1, 2, 3
Searching a free-form address list
There are several ways to find text in such a file. Suppose, for example, you want to contact your friend Scott, and you need his telephone number.
To output the line in the file containing the text "Scott", regardless of case, type:
$ grep -i scott rolo
The program will return
Scott F. - 602 555 1803 $
This works nicely when the information you need is on the same line as the information you search for -- here, the name Scott is on the same line as his telephone number; however, the output didn't show the warning that appears on the next line in the file. And what about when the term you search for and the information you need are on adjacent lines?
Use the -C option with grep to output two lines of
context before and after matched lines.
To output all lines matching the text "olfe" with two lines of context before and after the matched line, type:
$ grep -C olfe rolo
T. Wolfe's new email has changed.
The new one is: tw@example.com
$
Another way to search such a file is to open it as a buffer in Emacs and use any of the Emacs search
commands on it. The Emacs "incremental-search" function,
C-s ("control-s"), is very useful for such files. If you
type the characters to search for in all lower-case, Emacs matches
those characters regardless of case.
For example, to search through the current buffer in Emacs for the first entry containing the text "new york," regardless of case, type:
C-s new york
If you do such a search on a large file and the first result is not
the record you're looking for, just keep typing C-s until
the right one is matched.
So to search for the next entry containing the text "new york," regardless of case, type:
C-s
You can repeat this operation as many times as you wish to cycle through all places in the entire buffer where the text "new york" appears.