LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-17-2006, 03:46 PM   #1
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Rep: Reputation: 15
grep: grep for two substrings?


I'm trying to get grep to return true if it finds string xyz or string abc. I know you can do it with individual chars, but can this be accomplished with substrings? If so, how?

I.e.:

if cat /file | grep "xyz or abc"; then
echo "string contains substring xyz or substring abc"
fi

Last edited by eur0dad; 08-17-2006 at 03:47 PM.
 
Old 08-17-2006, 03:53 PM   #2
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora, Arch
Posts: 572

Rep: Reputation: 64
Try:
Code:
if cat file | grep 'xyz\|abc'; then
    echo "string contains substring xyz or substring abc"
fi
 
Old 08-17-2006, 04:03 PM   #3
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by KenJackson
Try:
Code:
if cat file | grep 'xyz\|abc'; then
    echo "string contains substring xyz or substring abc"
fi
Sweet. Thanks!
 
  


Reply

Tags
grep, script


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 12:22 PM
What does rpm -qa |grep th* (as compared to rpm -qa |grep th) display? davidas Linux - Newbie 2 03-18-2004 01:35 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM


All times are GMT -5. The time now is 06:54 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