LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to Linux Subscribe to Newsletters

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.

Pages: 1, 2, 3

Next Pagearrow




Tagged Articles

Be the first to post this article to del.icio.us

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com