Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

grep regular expression for this
grep should match a string like abc and should match whatever word
that follows it, and display
only these two matching words.

for example
-----------
abc
abc xyz
abcd
some text abc def

In the above file grep should match only lines 2 and 4 and give output

abc xyz
abc def

what can be the possible regular expressions

thanks
sinbad

Report this thread to moderator Post Follow-up to this message
Old Post
sinbad
03-31-08 10:47 AM


Re: grep regular expression for this
sinbad wrote:
> grep should match a string like abc and should match whatever word
> that follows it, and display
> only these two matching words.
>
> for example
> -----------
> abc
> abc xyz
> abcd
> some text abc def
>
> In the above file grep should match only lines 2 and 4 and give output
>
> abc xyz
> abc def
>
> what can be the possible regular expressions

$ echo "abc
abc xyz
abcd
some text abc def" | egrep -o 'abc +[[:alpha:]]+'
abc xyz
abc def



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
03-31-08 10:47 AM


Re: grep regular expression for this
In article <ER0Ij.14196$_v3.11547@edtnps90>,
"John W. Krahn" <someone@example.com> wrote:

> sinbad wrote: 
>
> $ echo "abc
> abc xyz
> abcd
> some text abc def" | egrep -o 'abc +[[:alpha:]]+'
> abc xyz
> abc def

I believe -o is a GNU grep extension.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***

Report this thread to moderator Post Follow-up to this message
Old Post
Barry Margolin
04-01-08 02:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:03 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.