LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-10-2008, 03:28 PM   #1
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Rep: Reputation: 30
Problem with simple grep command


For some reason I can't figure out how to get the "or" operator (i.e. "|") to work correctly. Consider the following command:

grep "<title>.*</title>|<p>.*</p>" file.txt

I simply want to get the lines which have the title and paragraph tags. However, the command will not work unless I do one at a time:

grep "<title>.*</title>" file.txt (works!)
grep "<p>.*</p>" file.txt (works!)


grep "<title>.*</title>|<p>.*</p>" file.txt (doesn't work!)
grep "<title>.*</title>\|<p>.*</p>" file.txt (doesn't work!)


Can anyone see what I'm doing wrong? (I'm new to grep btw).

Cheers.
 
Old 09-10-2008, 03:36 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
use the '-E' option. Extended regular expressions:
Code:
grep  -E "<title>.*</title>|<p>.*</p>" test.txt
 
Old 09-10-2008, 03:37 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
The logical or is part of extended regular expressions, for which you should use egrep.

*edit* or the -E option, as crc321 pointed out.
 
Old 09-10-2008, 06:01 PM   #4
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
Thanks everyone!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
simple read $a / grep question sycamorex Programming 2 01-08-2008 01:07 PM
problem with grep command thodo Linux - Newbie 1 10-25-2007 05:20 AM
Simple Linux command Problem GUIPenguin Linux - Newbie 2 09-23-2004 05:47 PM
Simple grep command problem acis Linux - General 2 07-16-2004 01:21 PM
Simple grep question - I hope ! MiguelE Linux - Newbie 3 04-16-2004 09:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:22 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration