LinuxQuestions.org
Help answer threads with 0 replies.
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 01-21-2010, 02:01 AM   #1
sagarkha
LQ Newbie
 
Registered: Nov 2009
Posts: 12

Rep: Reputation: 0
How to use regular expression in grep?


On my server, logs are saved in log.gz format. I want to know what regular expression should i use to search both oracle and a particular IP, say 1.2.3.4 in a single log line ?
 
Old 01-21-2010, 02:16 AM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
zcat log.gz | egrep "oracle|1.2.3.4"
 
Old 01-21-2010, 02:20 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by quanta View Post
zcat log.gz | egrep "oracle|1.2.3.4"
He wants AND, not OR.

And since he didn't say which comes first...
Code:
zcat log.gz | egrep "oracle.*1\.\2\.\3\.4|1\.\2\.\3\.4.*oracle"

Cheers,
Tink
 
Old 01-21-2010, 02:24 AM   #4
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
Quote:
Originally Posted by Tinkster View Post
He wants AND, not OR.
Sorry, I didn't read carefully.
 
Old 01-21-2010, 02:51 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,719

Rep: Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120
Wrong tool - grep doesn't like AND. At least I've never been able to get a "clean" answer. Use zcat piped to awk.
Code:
zcat log.gz | awk '/oracle/ && /1.2.3.4/'
 
Old 01-21-2010, 05:55 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
When I'm in a hurry, I just use 2 greps

zcat log.gz|grep oracle|grep '1.2.3.4'

or similar.
 
Old 01-23-2010, 08:15 AM   #7
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,031

Rep: Reputation: 63
Quote:
Originally Posted by sagarkha View Post
On my server, logs are saved in log.gz format. I want to know what regular expression should i use to search both oracle and a particular IP, say 1.2.3.4 in a single log line ?
Mark the thread as "[SOLVED]".It's under the "Thread Tools" above.
 
  


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
grep regular expression casperdaghost Linux - Newbie 2 08-15-2009 11:01 AM
grep Regular Expression lamar_air Programming 2 07-24-2006 03:40 PM
Help with grep regular expression lamar_air Programming 3 07-21-2006 11:26 AM
Regular Expression + not Working with grep scottwmackey Linux - General 2 06-21-2006 01:31 AM
problems with regular expression and grep bwreath Linux - General 6 03-18-2005 01:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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