Friday, March 26, 2010

Grepping ip address accurately

Let's say we have one log file named logfile.log that contains a few lines like below:

When we want to search for, we usually will use:

$ grep logfile.log

But unfortunately the result is not as what we expected(I assume we expect only will come out) because grep will show to us all results "containing" the pattern given by us.

To overcome this problem, we have to use grep like this:

$ grep "\>" logfile.log

Do not forget to put the double quotes, if not the command will not show any result.

That's all :)


Credit to for below technique, you can find the original post here

An alternative way to achive above result is by using -w flag of grep. So, instead of using grep "\>" logfile.log, you can also use grep -w logfile.log

No comments: