The system level log files usually keeps a lot of data about various applications and services . So at some times , we might need to grep only the IP communications from a large log file like ‘/var/log/messages’ or from syslog. The below command will grep only the data with IP addresses .
grep '[1-9]*\.[0-9]*\.[0-9]*\.[1-9]*' /var/log/messages
The * is used as a wild card to match anything or none .The backward slash is a escape character which instructs shell to avoid using it as a regular expression . Dot is a regular expression used to match any and the dash is used to declare the range on each octets . For the first and fourth octet , the first number should be higher than zero and for the second and third, the first number can be zero or higher .
Leave a Reply