LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Grep Expressions? (https://www.linuxquestions.org/questions/linux-general-1/grep-expressions-761624/)

Ordinary12 10-13-2009 11:54 AM

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?

David the H. 10-13-2009 01:52 PM

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.

never say never 10-13-2009 01:59 PM

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!

chrism01 10-13-2009 11:19 PM

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


All times are GMT -5. The time now is 05:04 AM.