Latest LQ Deal: Latest LQ Deals
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, 11:54 AM   #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, 01:52 PM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,846

Rep: Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008Reputation: 2008
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
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-13-2009, 11:19 PM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,782

Rep: Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538Reputation: 2538
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 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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:24 AM.

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