Portal Home > Knowledgebase > Articles Database > How do I make this grep return results "newest first" (date descending)?
How do I make this grep return results "newest first" (date descending)?
Posted by tnedator, 04-13-2012, 09:06 AM |
I'm trying to have an easy way of seeing mod_security hits in the access log, so I can determine if rules need to be whitelisted.
This grep works, but I really need it to display in reverse order, so I don't keep having to go through all the same entries over and over, hitting space bar, until I get to the new ones.
grep modsec_rules /usr/local/apache/logs/error_log | more
|
Posted by rcs, 04-13-2012, 09:12 AM |
grep has no option to show reverse order, however you can pipe the grep command through sort -r.
|
Posted by tnedator, 04-13-2012, 09:23 AM |
That almost worked, but it's not sorting quite right.
It put all of the Apr 11 entries before the Apr 12. It then sorted the Apr 11 in reverse order and then moved on to Apr 12 and put those in reverse order.
If there isn't a way to actually get it to properly sort, is there a way to put in multiple grep statements so that it grabbed only "Apr 12" and "modsec_rules"?
Would I do a grep, pipe it to another grap, then sort, then more???
|
Posted by rcs, 04-13-2012, 09:25 AM |
yeah, no problem with more pipes.
|
Posted by tnedator, 04-13-2012, 10:21 AM |
Thanks, my grep piped to grep, piped to sort, piped to more seems to get me what I need.
|
Add to Favourites Print this Article
Also Read