Unix Programming - grep and see only what I searched for

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2005 > grep and see only what I searched for





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author grep and see only what I searched for
Sashi

2005-07-15, 6:05 pm

Hi, I need to grep a group of files and I want to see only what I
searched for, as opposed to seeing the entier line which contains my
pattern. How do I do it?
For example:
This is a line from a file containing MyPattern and (other) words etc.
I just want to extract MyPattern from this line.
Thanks,
Shashi

Rouben Rostamian

2005-07-15, 6:05 pm

In article <1121434922.836687.245370@g14g2000cwa.googlegroups.com>,
Sashi <smalladi@gmail.com> wrote:
>Hi, I need to grep a group of files and I want to see only what I
>searched for, as opposed to seeing the entier line which contains my
>pattern. How do I do it?
>For example:
>This is a line from a file containing MyPattern and (other) words etc.
>I just want to extract MyPattern from this line.


Try sed instead:

sed -n '/.*\(MyPattern\).*/{s//\1/;p}' myfile

--
rr
Maxim Yegorushkin

2005-07-15, 6:05 pm

On Fri, 15 Jul 2005 17:42:02 +0400, Sashi <smalladi@gmail.com> wrote:

> Hi, I need to grep a group of files and I want to see only what I
> searched for, as opposed to seeing the entier line which contains my
> pattern. How do I do it?


man bash

....
-o, --only-matching

--
Maxim Yegorushkin
<firstname.lastname@gmail.com>
Bill Marcum

2005-07-16, 2:48 am

On Fri, 15 Jul 2005 22:30:40 +0400, Maxim Yegorushkin
<firstname.lastname@gmail.com> wrote:
> On Fri, 15 Jul 2005 17:42:02 +0400, Sashi <smalladi@gmail.com> wrote:
>
>
> man bash
>
> ...
> -o, --only-matching
>

Did you mean "man grep"? -o is a GNU grep option.



--
Tonight you will pay the wages of sin; Don't forget to leave a tip.
Maxim Yegorushkin

2005-07-17, 5:50 pm

On Sat, 16 Jul 2005 11:20:13 +0400, Bill Marcum <bmarcum@iglou.com.urgent>
wrote:

> Did you mean "man grep"? -o is a GNU grep option.


Yes, my mistake.

--
Maxim Yegorushkin
<firstname.lastname@gmail.com>
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com