LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 10-13-2009, 11:54 AM   #1
Ordinary12
Member
 
Registered: Feb 2007
Posts: 140

Rep: Reputation: 15
Grep Expressions?


Hello Everyone:

I'm using the grep command to search through very large proxy logs and it works great but I've been unable to string together a grep expression that will allow me to search for two distinct fields. I've been searching for IP address only but can someone tell me what the grep expression is to perform a search for IP address and website is?
 
Old 10-13-2009, 01:52 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
It would help if you provided an example of the input and the expected output.

But to start with, have a look at the "-e" option.
 
Old 10-13-2009, 01:59 PM   #3
never say never
Member
 
Registered: Sep 2009
Location: Indiana, USA
Distribution: SLES, SLED, OpenSuse, CentOS, ubuntu 10.10, OpenBSD, FreeBSD
Posts: 195

Rep: Reputation: 37
Couple of options

If you aren't terribly concerned with efficiency, you can always do something like this:

grep xxx.xxx.xxx.xxx /var/log/logfile | grep google.com

You will only get lines that pass both tests. The first grep acts on the logfile and the second grep acts on the output of the first.

This a quick and dirty way to narrow the results to only the lines you are interested in.

If you are trying to script something or you just want to be a bit more elegant, you will need to do a regular expression.

It would be helpful to see a part of the log file you are searching as reg ex can be challenging to get right sometimes.

Hope this helps!
 
Old 10-13-2009, 11:19 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,287

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Sounds like example 4 http://www.thegeekstuff.com/2009/03/...mand-examples/ is along the right lines.
 
  


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
using grep with expressions ANDed logicalfuzz Linux - Newbie 20 11-16-2010 12:17 AM
[SOLVED] Why this grep command with regular expressions not working on my system? Andrew Dufresne Linux - Newbie 12 10-01-2009 02:38 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM
Commands and Common Expressions-ls/grep rtrahan Linux - Newbie 4 02-17-2009 07:48 AM
Regular expressions using grep linuxmandrake Programming 3 11-16-2005 04:29 PM


All times are GMT -5. The time now is 07:54 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration