GNU grep's New Trick
Colored output mode and matching only mode are very useful.
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.
Re: GNU grep's New Trick
nice tip. Although I don't know which version of grep(cygwin) I use, I know that it has the -o option. I don't use the color optins since the terminal I use is COLOR DEAD(cmd.exe terminal from microsoft).
Does anyone know if I can get XEmacs to use a different termainal when I run shell within it (on windows) ?
I use REgex Coach(http://www.weitz.de/regex-coach/) and XEmacs to experiment with Regexes. Xemacs can be a pain since you have to escape \(backslash) and even though I'm inside emacs, I get out to Regex Coach and use its LISP engine for the regex stuff --- highly recommended.
BR,
~A