LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-31-2009, 02:02 AM   #1
kapila
LQ Newbie
 
Registered: Feb 2008
Posts: 9

Rep: Reputation: 0
grep exact pattern


Hello,

Need to find a particular pattern from a file-

$grep -w "titan/WEB-INF/resources/mmt_engine.properties" a
titan/WEB-INF/resources/mmt_engine.properties.b2c.prod 1.2.2.1
titan/WEB-INF/resources/mmt_engine.properties 1.2.2.1
titan/WEB-INF/resources/mmt_engine.properties.b2c.prod 1.2.2.2


where i need only result as-
titan/WEB-INF/resources/mmt_engine.properties 1.2.2.1

how can i do this?

regards
Kapila
 
Old 07-31-2009, 02:05 AM   #2
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,270

Rep: Reputation: 99
Quote:
Originally Posted by kapila View Post
Hello,

Need to find a particular pattern from a file-

$grep -w "titan/WEB-INF/resources/mmt_engine.properties" a
titan/WEB-INF/resources/mmt_engine.properties.b2c.prod 1.2.2.1
titan/WEB-INF/resources/mmt_engine.properties 1.2.2.1
titan/WEB-INF/resources/mmt_engine.properties.b2c.prod 1.2.2.2


where i need only result as-
titan/WEB-INF/resources/mmt_engine.properties 1.2.2.1

how can i do this?

regards
Kapila
You can do,

Code:
grep -w  "titan/WEB-INF/resources/mmt_engine.properties " a
Mind that extra space after properties.

Hope this helps
 
Old 07-31-2009, 02:06 AM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
grep 'titan/WEB-INF/resources/mmt_engine.properties 1.2.2.1' somefile

note single quotes, not backquotes
 
Old 07-31-2009, 05:20 AM   #4
kapila
LQ Newbie
 
Registered: Feb 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks all for your replies.
But have tried with -w & -x option keeping pattern in quotes. its gives same thing.
My command knows pattern in which version 1.2.1.2 is not known.
 
Old 07-31-2009, 05:23 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
What if you add a trailing space in the pattern, as suggested by Vikas above?

Last edited by colucix; 07-31-2009 at 05:24 AM.
 
Old 07-31-2009, 10:09 AM   #6
kapila
LQ Newbie
 
Registered: Feb 2008
Posts: 9

Original Poster
Rep: Reputation: 0
I have tried command like
grep -w "pattern " file

but this also fails then
 
Old 07-31-2009, 10:20 AM   #7
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
At this point is not clear what is the result you expect. Please, can you post the input file (or a relevant part of it) and the desired result? Use CODE tags to preserve the original formatting of the file (spacing, indentation and so on). Thanks.
 
Old 07-31-2009, 11:03 AM   #8
joeBuffer
Member
 
Registered: Jul 2009
Distribution: Ubuntu 9.04
Posts: 328

Rep: Reputation: 42
Like colucix said, more information would be nice.
Without knowing the layout of the file you are trying to get this data from, you could use awk to do:

Code:
awk '$1 ~ /titan\/WEB-INF\/resources\/mmt_engine.properties/ && $1 !~ /.b2c.prod/ && $2 ~ /1.2.2.1/' file

Last edited by joeBuffer; 07-31-2009 at 11:17 AM. Reason: I messed my post all up, thinking that you had posted you were trying to match the line with ....b2c.prod 1.2.2.1 in it.
 
Old 08-04-2009, 01:40 AM   #9
kapila
LQ Newbie
 
Registered: Feb 2008
Posts: 9

Original Poster
Rep: Reputation: 0
when i do --

>>grep "titan/WEB-INF/resources/mmt_engine.properties" a
get o/p as -->

titan/WEB-INF/resources/mmt_engine.properties.b2c.prod 1.2.2.1
titan/WEB-INF/resources/mmt_engine.properties 1.2.2.1
titan/WEB-INF/resources/mmt_engine.properties.b2c.prod 1.2.2.2


I want output as -
titan/WEB-INF/resources/mmt_engine.properties 1.2.2.1

So constant pattern known is – “titan/WEB-INF/resources/mmt_engine.properties” not version !!



So I should be able to do something like-
>>grep "titan/WEB-INF/resources/mmt_engine.properties" a--- how????
o/p
titan/WEB-INF/resources/mmt_engine.properties 1.2.2.1


any help?
 
Old 08-04-2009, 06:32 AM   #10
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,270

Rep: Reputation: 99
Quote:
Originally Posted by kapila View Post
any help?
Please refer to my earlier post. This can not fail.

Code:
grep -w  "titan/WEB-INF/resources/mmt_engine.properties " a
There is an extra space after properties, how could you get same result ? It CAN NOT search character after properties (.b2c.prod) in your case.

Please find my logs.
Code:
-sh-3.00$ cat a
titan/WEB-INF/resources/mmt_engine.properties.b2c.prod  1.2.2.1
titan/WEB-INF/resources/mmt_engine.properties   1.2.2.1
titan/WEB-INF/resources/mmt_engine.properties.b2c.prod  1.2.2.2
-sh-3.00$
-sh-3.00$ grep -w "titan/WEB-INF/resources/mmt_engine.properties " a
titan/WEB-INF/resources/mmt_engine.properties   1.2.2.1
 
Old 08-06-2009, 01:40 AM   #11
kapila
LQ Newbie
 
Registered: Feb 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Doesn't work

svn CCR-Tag # grep -w "titan/WEB-INF/resources/mmt_engine.properties " a
svn CCR-Tag #..

I tried teh same with extra space. Its giving nothing
 
Old 08-06-2009, 03:58 AM   #12
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Are you sure it's a space between properties and version, not a tab character or other whitespace?

You can try
Code:
wim@btd-techweb01:~/test/lq744068$ grep  "titan/WEB-INF/resources/mmt_engine.properties[[:space:]]" a
titan/WEB-INF/resources/mmt_engine.properties   1.2.2.1
titan/WEB-INF/resources/mmt_engine.properties   1.2.2.x
The latter one contains a tab character
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to match the exact pattern using grep utility vinaytp Linux - Newbie 3 05-11-2009 01:36 AM
command for grep the exact word nagendrar Linux - Newbie 7 04-29-2009 03:33 PM
grep the exact string only ZAMO Linux - General 11 08-28-2008 06:08 AM
grep exact letters packets Linux - Newbie 1 11-30-2007 09:39 PM
grep [exact phrase] chrisfirestar Linux - General 2 02-09-2004 05:30 AM


All times are GMT -5. The time now is 11:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration