I have a bash script which takes a log file with each record separated by a #. The records have multiple fields but field $1 is always the date and time. When the script is run it prints the record just fine from oldest to newest. I need to have records print out from newest first.
Here is the part of the code:
03-31-2010 00:13:51
ab1234
SUBMITTED FROM URL: tool.cgi
show mem
#
03-31-2010 00:15:35
bc1234
SUBMITTED FROM URL: tool.cgi
show mem
sh ip access-list PROTECT_RE
#
03-31-2010 12:51:20
de1234
SUBMITTED FROM URL: ncg.cgi
vi aaa
sho subscribers username
#
03-31-2010 12:51:39
fg1234
SUBMITTED FROM URL: config_ncg.cgi
vi bbb
sho subscribers username
#
Needs to be printed out like this:
03-31-2010 12:51:39
fg1234
SUBMITTED FROM URL: config_ncg.cgi
vi bbb
sho subscribers username
#
03-31-2010 12:51:20
de1234
SUBMITTED FROM URL: ncg.cgi
vi aaa
sho subscribers username
#
03-31-2010 00:15:35
bc1234
SUBMITTED FROM URL: tool.cgi
show mem
sh ip access-list PROTECT_RE
#
03-31-2010 00:13:51
ab1234
SUBMITTED FROM URL: tool.cgi
show mem
#
The idea behind this is to display the log content via a browser. I have some filters to only print records that have a match. But mostly, I just need it to dispay from newest record first.
The orginal data file looks like:
#
03-31-2010 00:13:51
ab1234
SUBMITTED FROM URL: tool.cgi
show mem
#
03-31-2010 00:15:35
bc1234
SUBMITTED FROM URL: tool.cgi
show mem
sh ip access-list PROTECT_RE
#
03-31-2010 12:51:20
de1234
SUBMITTED FROM URL: ncg.cgi
vi aaa
sho subscribers username
#
03-31-2010 12:51:39
fg1234
SUBMITTED FROM URL: config_ncg.cgi
vi bbb
sho subscribers username
#
The output looks the same but without the #
03-31-2010 00:13:51
ab1234
SUBMITTED FROM URL: tool.cgi
show mem
03-31-2010 00:15:35
bc1234
SUBMITTED FROM URL: tool.cgi
show mem
sh ip access-list PROTECT_RE
03-31-2010 12:51:20
de1234
SUBMITTED FROM URL: ncg.cgi
vi aaa
sho subscribers username
03-31-2010 12:51:39
fg1234
SUBMITTED FROM URL: config_ncg.cgi
vi bbb
sho subscribers username
One more obstacle for me to over come. I need to put an if statement in the nawk statement. I only want it to print if field2 starts with my date variable and of course in reverse order.