I have a directory full of logs named in the following style:
info.log00001 info.log00002 info.log00003 ... info.log09999 info.log
My current output (using grep -c)
I need to analyze the frequency a particular error that happens occasionally, so go to that directory and use
grep -crw . -e "FooException BarError" | sort -n | less obtaining something like:
./info.log00001: 1 ./info.log00002: 0 ./info.log00003: 42 ... ./info.log09999: 25 ./info.log: 0
Then, I can
ls -lt to see their modification date and analyze when the error happened the most.
My desired output (with count and date)
Anyway, I'd like find a way to get an output with the count and the date in the same line. That would make my analysis easier. I would like something as:
2015-09-31 10:00 ./info.log00001: 1 2015-09-31 10:15 ./info.log00002: 0 2015-09-31 10:30 ./info.log00003: 42 ... 2016-04-01 13:20 ./info.log09999: 25 2015-09-31 13:27 ./info.log: 0
Ideally, I'd like to accomplish this with only one command, but first throwing
grep's output to a file and then processing that file would make it, too.
Also, I really don't care about the date format or whether the date is at the end or at the beginning of the line. All I want to to is to have the files sorted by date starting with the oldest (which is also the file with the lowest number in its name)
I found a way to accomplish something similar with
awk, but in my case it would not work, since it parses the filename from
grep's output, and in my case,
grep's output has more text that just the path to the file.
I'd really appreciate any feedback on this.