LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 04-14-2010, 04:38 AM   #1
msgforsunil
Member
 
Registered: Jun 2006
Posts: 33

Rep: Reputation: 15
egrep for only words(exact match)


Hi All,

I have the below file content
<sunilkumar@test5>more test.ksh
movie work
a or b
clear

Query1: For the below command, is there anyway, I can see the strings not found as part of search. For eg. the command should output "and" is not found

Query 2: For the below command, is there any way, I can list only "a or b" and not "movie work"; I meant exact word search. If yes, how do I do that?

<sunilkumar@test5>egrep -i "or|and" test.ksh
movie work
a or b
 
Old 04-14-2010, 04:58 AM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
For your second query add word boundaries to your search
Code:
egrep --color -i "\bor|and\b" test.ksh
for more info look in to the man pages
Code:
man egrep
 
Old 04-14-2010, 05:07 AM   #3
msgforsunil
Member
 
Registered: Jun 2006
Posts: 33

Original Poster
Rep: Reputation: 15
I am not getting output. Please see the results below. Can you please paste the command and the output as well?

Thanks,
Sunil Kumar



<sunilkumar@test5>egrep --color -i "\bor|and\b" test.ksh
egrep: illegal option -- -
egrep: illegal option -- o
egrep: illegal option -- o
egrep: illegal option -- r
usage: egrep [ -bchilnsv ] [ -e exp ] [ -f file ] [ strings ] [ file ] ...
<sunilkumar@test5>egrep -i "\bor|and\b" test.ksh
<sunilkumar@test5>egrep -i "\bor\b" test.ksh
<sunilkumar@test5>
 
Old 04-14-2010, 05:11 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
It worked for me which distro is this ?
 
Old 04-14-2010, 05:27 AM   #5
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
egrep -i ' (or|and) ' test.ksh
 
1 members found this post helpful.
  


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 cut exact words within a file luzner Linux - Newbie 2 07-25-2007 08:15 AM
Exact words verbatim to go in boot menu1st salah-ad-din MEPIS 5 07-10-2006 12:17 PM
nice egrep 300 search words in one go? shalomajay LinuxQuestions.org Member Intro 2 03-01-2006 05:31 PM
nice egrep 300 search words in one go? shalomajay Programming 1 03-01-2006 03:21 PM
how to find an exact substring match? ldp Programming 7 02-22-2005 06:28 AM


All times are GMT -5. The time now is 08:19 AM.

Main Menu
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