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: 101Reputation: 101
zcat log.gz | egrep "oracle|1.2.3.4"
 
Old 01-21-2010, 02:20 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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: 101Reputation: 101
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: 21,236

Rep: Reputation: 4150Reputation: 4150Reputation: 4150Reputation: 4150Reputation: 4150Reputation: 4150Reputation: 4150Reputation: 4150Reputation: 4150Reputation: 4150Reputation: 4150
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: Rocky 9.2
Posts: 18,388

Rep: Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774
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
Posts: 1,045

Rep: Reputation: 65
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 07:04 AM.

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
Open Source Consulting | Domain Registration