View the Most Wanted LQ Wiki articles.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 10-13-2009, 12:54 PM   #1
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, 02: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: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954
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, 02:59 PM   #3
never say never
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 /var/log/logfile | grep

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-14-2009, 12:19 AM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.7, Centos 5.10
Posts: 16,917

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Sounds like example 4 is along the right lines.


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 01:17 AM
[SOLVED] Why this grep command with regular expressions not working on my system? Andrew Dufresne Linux - Newbie 12 10-01-2009 03: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 11:31 PM
Commands and Common Expressions-ls/grep rtrahan Linux - Newbie 4 02-17-2009 08:48 AM
Regular expressions using grep linuxmandrake Programming 3 11-16-2005 05:29 PM

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