I have a directory full of logs named in the following style:  info.log00001info.log00002info.log00003...info.log09999info.logMy 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: 0Then, 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: 12015-09-31 10:15 ./info.log00002: 02015-09-31 10:30 ./info.log00003: 42...2016-04-01 13:20 ./info.log09999: 252015-09-31 13:27 ./info.log: 0Additional infoIdeally, 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.
Add mtime to grep -c output and sort the output by mtime
command line;text processing;files;awk;grep
If you have gnu find - and assuming none of your file names contains newlines - you could use find's -printf to output the mtime in the desired format + the file name then run grep to get the count:find . -type f -printf '%TY-%Tm-%Td %TH:%TM %p: ' -exec grep -cw whatever {} \; | sort -k1,1 -k2,2Alternatively, with zsh you could glob and sort by modification time (via glob qualifiers - . selects regular files, Om sorts in descending order by mtime) and then for each file print the mtime using the stat module, the file name and then, again, get the count via grep:zmodload zsh/statfor f in ./**/*(.Om)doprintf '%s %s\t%s %s: ' $(zstat -F '%Y-%b-%d %H:%M' +mtime -- $f) $fgrep -cw whatever  $fdone