Separate file entries based on date.

January 10, 2013 at 07:28:38
Specs: Solaris

Hi Experts,

I would like to seek your assitance in creating a script for the following scenario:

Single file has different entries with carriage return as record separator. Goal is to produce separate file based on date. Each entry has variable number of length.


## INPUT
--------------------------------------------------------------------------
Sun Dec 09 02:02:03 2012
Stop
PPP
IP
PortDetail

Sun Dec 10 02:29:03 2012
Alive
Framed
MAC

Sun Dec 09 02:31:03 2012
Stop
Framed
PPP

Sun Dec 10 14:02:03 2012
Stop
Framed
PPP
MAC

Sun Dec 10 02:31:03 2012
Stop
Framed
PPP
--------------------------------------------------------------------------

## OUTPUT
--------------------------------------------------------------------------

~cat Entries_Dec09
Sun Dec 09 02:02:03 2012
Stop
PPP
IP
PortDetail

Sun Dec 09 02:31:03 2012
Stop
Framed
PPP

~cat Entries_Dec 10
Sun Dec 10 02:29:03 2012
Alive
Framed
MAC


Sun Dec 10 14:02:03 2012
Stop
Framed
PPP
MAC

Sun Dec 10 02:31:03 2012
Stop
Framed
PPP

--------------------------------------------------------------------------

Can this be achieved using awk? Any input is highly appreciated.


Thanks and Regards,
Amiti


See More: Separate file entries based on date.

Report •


#1
January 10, 2013 at 09:27:15

Last May, I answered a similar awk question for you which redirects output to a file:

http://www.computing.net/answers/un...

Anyway, this should get you started:

#!/bin/ksh

awk ' {
if($2 == "Dec" || $2 == "Jan")
   fn="Entries_"$2$3

print $0 >> fn
}' data.txt



Report •
Related Solutions


Ask Question