LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Filter Search Results (https://www.linuxquestions.org/questions/linux-software-2/filter-search-results-442795/)

wwnexc 05-08-2006 10:37 AM

Filter Search Results
 
Hi,

I have been running a little server for a while, and i am wondering how many people have used it. The server creates crappy logfiles.

I am trying to find the command which would allow me to print only the matching characters per line in the input file and follw each result with a line break.

The results therefore should look something like this (a list of all ip addresses from a bunch of crappy logfiles):
Code:

64.1.2.3
126.89.42.22
5.23.95.45
...

and so on.

I was thinking about a program which matches something like this:
Code:

[:digit:]\{1,3\}\.[:digit:]\{1,3\}\.[:digit:]\{1,3\}\.[:digit:]\{1,3\}
(I hope the above regular expression is correct. It should match all numbers in the following pattern nnn.nnn.nnn.nnn

The program is only supposed to print matches of the expression, not the entire line of its context.

THANKS!!

frankjoshua 05-08-2006 11:06 AM

Try this:
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' /var/log/mylog.log
or
dmesg | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

you must have the slashes and single quotes.


All times are GMT -5. The time now is 07:29 AM.