Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-16-2007, 08:35 PM   #1
Registered: Oct 2004
Location: /usr/home
Distribution: Fedora, Mint, FreeBSD, Android
Posts: 352

Rep: Reputation: 32
grep CLI syntax: how to find A OR B?

I can't get figure out how to alternation to work on the command line. Something like this doesn't work:

$ grep \(the\|and\) somefile.txt

nor this:

$ grep "(the|and)" somefile.txt

What's the secret?
Old 01-16-2007, 08:44 PM   #2
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
egrep 'the|land' somefile
Old 01-16-2007, 10:09 PM   #3
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
What anomie said, or you could try:
grep -e the -e and somefile.txt
Old 01-16-2007, 10:45 PM   #4
Registered: Oct 2004
Location: /usr/home
Distribution: Fedora, Mint, FreeBSD, Android
Posts: 352

Original Poster
Rep: Reputation: 32
Just what I was looking for, thanks.


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
grep script/syntax carriehoff Linux - Newbie 6 08-31-2006 02:13 PM
need help with find syntax stefaandk Linux - General 4 07-12-2006 06:48 PM
Grep syntax questions Phaethar Linux - General 4 04-11-2005 10:34 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 07:09 PM
help me find grep-2.5.1 shanenin Linux - Software 1 01-23-2004 10:01 PM

All times are GMT -5. The time now is 06:46 PM.

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