Skip to main content
1 of 3
terdon
  • 252.3k
  • 69
  • 480
  • 718

If it is enough to just have one log file per day, you can do:

awk '($1~/[0-9]*-[0-9]*-[0-9]*/){d=$1}{print > d".log"}' logfile 

For example, if you have the data in your question saved in logfile, the above will produce:

$ ls
2014-04-07.log  2014-04-08.log  2015-04-08.log  logfile
$ for i in *log; do echo "=== $i ==="; cat $i; done
=== 2014-04-07.log ===
2014-04-07 23:59:58 CheckForCallAction [ERROR] Exception caught
Undated line 1
Undated line 2
=== 2014-04-08.log ===
2014-04-08 00:00:03 MobileAppRequestFilter [DEBUG] Action
undated line 3
=== 2015-04-08.log ===
2015-04-08 00:00:03 MobileAppRequestFilter [DEBUG] ActionB

Explanation

  • ($1~/[0-9]*-[0-9]*-[0-9]*/){d=$1} : if the first field of this line looks like a date string, set the variable d to the first field.
  • {print > d".log"} : print each line into a file whose name is the current value of d with the extension ".log".
terdon
  • 252.3k
  • 69
  • 480
  • 718