Visit Jeremy's Blog.
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 10-13-2007, 08:37 AM   #1
LQ Newbie
Registered: Oct 2007
Posts: 4

Rep: Reputation: 0
grep command - 3 different expresions

I have a problem:
I am trying to create a single grep command that checks if 3 different expirations are in a specific file.

right now what I am using is 3 different commands as follows:

grep -r -l "Error can't open" x/*.txt
grep -r -l "rsync error" x/*.txt
grep -r -l "can't aquire" x/*.txt

But as I said I want them all in one command to make it easier for me.

please advise
Old 10-13-2007, 08:54 AM   #2
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Use egrep:
 egrep -r -l "Error can't open|rsync error|can't aquire" x/*.txt
This shows the file name if it contains any one of the three messages.

Last edited by Disillusionist; 10-13-2007 at 08:56 AM.
Old 10-13-2007, 10:27 AM   #3
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
You can also specify multiple expressions with the -e option, e.g.
grep -rl -e "I hope" -e "This isn't" -e "Homework" x/*.txt

Last edited by matthewg42; 10-13-2007 at 12:08 PM.
Old 10-14-2007, 03:32 PM   #4
LQ Newbie
Registered: Oct 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks guys

Thanks it works
helped me alot


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
Help Use Grep Command, Thanks! zzytech Linux - Newbie 2 04-05-2006 11:37 PM
Bash: How can i use variables for grep regular expresions ? landuchi Linux - General 4 01-21-2006 11:57 PM
grep command in c????? alnreddy Linux - Software 1 12-30-2004 01:01 AM
Regular Expresions on C++ poeta_boy Programming 7 06-18-2004 12:00 AM
Help With GREP Command juliettree Linux - Newbie 3 04-08-2004 08:44 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:32 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
Open Source Consulting | Domain Registration