The Artima Developer Community
Sponsored Link

Java Buzz Forum
GNU grep's New Trick

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
GNU grep's New Trick Posted: Jun 10, 2006 10:24 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: GNU grep's New Trick
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

I stumbled upon this Linux.com article: GNU grep's new features about a week ago. (No, the StumbleUpon Firefox plugin was not used.) I printed it out but only got a chance reading it on Thursday.

It talked about several new features in GNU grep 2.5 that's pretty neat. I've already used two of the features at work yesterday. But before I go on, let me see a show of hands, how many of you are using GNU grep 2.5? 2.4? 2.0? Right, chances are that you don't know or much care which version of grep you are using. I didn't know until I read the article. (I'm using GNU grep 2.5.1, which is a patch level behind the latest release. Must download, ./configure; make; make check; make install! ...Not! By the way, 2.5 was out in 2002—four years ago.)

The features I used are called --only-matching and --color. The --only-matching feature can also be specified using the -o option on the command line and it shows only the part of a matching line that matches PATTERN. The --color feature will show the matching portion of the line in color (by default red).

I find myself using the --color option to experiment with the regular expressions and then using the -o option to get the matching text for further processing:

[weiqi@gao]$ cat foo
This is a test.
[weiqi@gao]$ grep --color test foo
This is a test.
[weiqi@gao]$ grep -o test foo
test

For more complicated regular expressions, the color option gives a better visual feedback.

Give these new options a try.

Read: GNU grep's New Trick

Topic: DrunkAndRetired.com: Buñuelos! Previous Topic   Next Topic Topic: WordPress 2.0.3 Released

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use