Sort by Duration

        ..........................................................................................................................         
           03:40   Geonetric File from         CCL                         Complete    03:40:59 03:41:08 00:00:09 00:00:01    N/A
                   005  sys_runccl                                         Complete    03:41:00 03:41:08 00:00:08 00:00:01    N/A
                        Bat:  edtat_2
                        Out:
                        Evt:  Operations - Complete
                   010  sys_osscript                                       Complete    03:41:08 03:41:08 00:00:00 00:00:00    N/A
                        Bat:  
                        Evt:  Operations - Complete
                        Tz :  America/New_York
         ..........................................................................................................................
         04:00   Geonetric File from 					   Complete    04:00:00 04:00:06 00:00:06 00:00:01    N/A
                   005  sys_runccl                                         Complete    04:00:00 04:00:06 00:00:06 00:00:01    N/A
                        Bat:  edtat_2
                        Out:
                        Evt:  Operations - Complete
                   010  sys_osscript                                       Complete    04:00:06 04:00:06 00:00:00 00:00:00    N/A
                        Bat:  /geonetrics_ftp.ksh
                        Evt:  Operations - Complete
                        Tz :  America/New_York
         ..........................................................................................................................
         04:15   Downtime Comp Rounds List                                 Complete    04:15:01 04:23:21 00:08:20 00:08:43    N/A
                   010  sys_runccl                                         Complete    04:15:01 04:22:26 00:07:25 00:06:01    N/A
                        Bat:  
                        Out:
         ..........................................................................................................................
         06:58   Radiology Cancer Care                                     Complete    06:58:09 06:58:28 00:00:19 00:03:13    N/A
                   005  cp_process_dist                                    Complete    06:58:09 06:58:28 00:00:19 00:03:13    N/A
                        Bat:  SGAH Radiology Cancer Care
                        Out:
                        Evt:  Operations - Complete
         ..........................................................................................................................
         07:00   Rad Provider Copy                                         Complete    07:00:09 07:00:15 00:00:06 00:00:43    N/A
                   005  cp_process_dist                                    Complete    07:00:09 07:00:15 00:00:06 00:00:43    N/A
                        Bat:  HRMC Rad Provider Copy
                        Out:
                        Evt:  Operations - Zero
         ..........................................................................................................................


I have a long report like this and need to sort by "Duration", which is the column far right with the timestamp.
Each "block" with "......................." can have multiple lines. The key timestamp for sorting is far right and top regardless a number of lines in the "block".
Please advise.

Where is that? I see several things in each entry which could qualify...

  ..........................................................................................................................
         04:00   Geonetric File from 					   Complete    04:00:00 04:00:06 00:00:06 00:00:01    N/A
                   005  sys_runccl                                         Complete    04:00:00 04:00:06 00:00:06 00:00:01    N/A
                        Bat:  edtat_2
                        Out:
                        Evt:  Operations - Complete
                   010  sys_osscript                                       Complete    04:00:06 04:00:06 00:00:00 00:00:00    N/A
                        Bat:  /geonetrics_ftp.ksh
                        Evt:  Operations - Complete
                        Tz :  America/New_York
         ..........................................................................................................................

For this "block", i.e.
04:00 Geonetric File from Complete 04:00:00 04:00:06 00:00:06 00:00:01 N/A
00:00:01 is the one, which is far right and top.

---------- Post updated at 04:33 PM ---------- Previous update was at 04:31 PM ----------

 ..........................................................................................................................
         04:15   Downtime Comp Rounds List                                 Complete    04:15:01 04:23:21 00:08:20 00:08:43    N/A
                   010  sys_runccl                                         Complete    04:15:01 04:22:26 00:07:25 00:06:01    N/A
                        Bat:  
                        Out:

for this block, it is 00:08:43

You may need GNU awk for this:

# Convert ....... lines into blank lines, put in file 'newdata'
sed 's/^ *[.]* *$//' data > newdata
# Print duration record-number and sort it, put in file 'order'
awk -F"\n" -v RS="" '{ L=split($1, A, " "); print A[L-1], NR; }' newdata | sort > order

# Read the 'order' file to decide what order to print
# Read all records
# Print all records in the order given by 'order'
awk 'BEGIN {
        printf("..........................................................................................................................\n");

        while((getline <"order")>0) { O[++L]=$2 }
        RS=""
	ORS="\n        ..........................................................................................................................\n"
}
{ D[NR]=$0 }

END { for(N=1; N<=NR; N++) print D[O[N]]; }' newdata > sorted

# Remove temporary files
rm -f newdata order
        ..........................................................................................................................
                                              Operations Activity Report (Continued)                                     Page:  138
        ..........................................................................................................................
                                              Operations Activity Report (Continued)                                     Page:  139
        ..........................................................................................................................
                                              Operations Activity Report (Continued)                                     Page:  141
        ..........................................................................................................................
                                              Operations Activity Report (Continued)                                     Page:  142
        ..........................................................................................................................
                                              Operations Activity Report (Continued)                                     Page:  144
        ..........................................................................................................................
                                              Operations Activity Report (Continued)                                     Page:  146
        ..........................................................................................................................
                                              Operations Activity Report (Continued)                                     Page:  148
        ..........................................................................................................................
                                              Operations Activity Report (Continued)                                     Page:  149
        ..........................................................................................................................
         06:00   PowerNote ED Open Notes Report - ED                  Not Started                            Runtms<5    N/A
                   001  ccl_run_program_from_ops                           Not Started                            Runtms<5    N/A
                        Bat:  pha_updt_rtc_on_fph
                        Tz :  0
        ..........................................................................................................................
         06:00   EKG Charge (Bill) File                                    Complete    06:00:03 06:03:57 00:03:54 Runtms<5    N/A
        ..........................................................................................................................
         06:05   EKG Demographic File                                      Complete    06:05:04 06:05:26 00:00:22 Runtms<5    N/A
                   001  ccl_run_program_from_ops                           Complete    06:05:04 06:05:26 00:00:22 Runtms<5    N/A
                        Bat:  adv_lds_ekg_demo_rpt_ops2

It seems skipping the "block".

Can we give it another approach?
If any of "duration" is greater than 03:00:00 in the "block" within "...........", can we extract those entire "block"s out?

Please advise.

It definitely works here on the data you've given. What's your system?

Also, it just occurred to me -- might the file have carriage returns in it?

I am on AIX 6.1. It is a long file, so there might be cr somewhere ....

Hi Daniel Gate,

One way using perl:

$ cat infile
        ..........................................................................................................................         
           03:40   Geonetric File from         CCL                         Complete    03:40:59 03:41:08 00:00:09 00:00:01    N/A
                   005  sys_runccl                                         Complete    03:41:00 03:41:08 00:00:08 00:00:01    N/A
                        Bat:  edtat_2
                        Out:
                        Evt:  Operations - Complete
                   010  sys_osscript                                       Complete    03:41:08 03:41:08 00:00:00 00:00:00    N/A
                        Bat:  
                        Evt:  Operations - Complete
                        Tz :  America/New_York
         ..........................................................................................................................
         04:00   Geonetric File from                                       Complete    04:00:00 04:00:06 00:00:06 00:00:01    N/A
                   005  sys_runccl                                         Complete    04:00:00 04:00:06 00:00:06 00:00:01    N/A
                        Bat:  edtat_2
                        Out:
                        Evt:  Operations - Complete
                   010  sys_osscript                                       Complete    04:00:06 04:00:06 00:00:00 00:00:00    N/A
                        Bat:  /geonetrics_ftp.ksh
                        Evt:  Operations - Complete
                        Tz :  America/New_York
         ..........................................................................................................................
         04:15   Downtime Comp Rounds List                                 Complete    04:15:01 04:23:21 00:08:20 00:08:43    N/A
                   010  sys_runccl                                         Complete    04:15:01 04:22:26 00:07:25 00:06:01    N/A
                        Bat:  
                        Out:
         ..........................................................................................................................
         06:58   Radiology Cancer Care                                     Complete    06:58:09 06:58:28 00:00:19 00:03:13    N/A
                   005  cp_process_dist                                    Complete    06:58:09 06:58:28 00:00:19 00:03:13    N/A
                        Bat:  SGAH Radiology Cancer Care
                        Out:
                        Evt:  Operations - Complete
         ..........................................................................................................................
         07:00   Rad Provider Copy                                         Complete    07:00:09 07:00:15 00:00:06 00:00:43    N/A
                   005  cp_process_dist                                    Complete    07:00:09 07:00:15 00:00:06 00:00:43    N/A
                        Bat:  HRMC Rad Provider Copy
                        Out:
                        Evt:  Operations - Zero
         ..........................................................................................................................

$ cat script.pl
#!/usr/bin/env perl

use warnings;
use strict;

my $sep = qq|\n| . q|.| x 100 . qq|\n|;

my @data = 
        join $sep,
        map { $_->[1] } 
        sort { $a->[0] <=> $b->[0] } 
        map { m|(\d{2}):(\d{2}):(\d{2})\s+N/A|; [ $1 . $2 . $3, $_ ] }
        grep { /\S/ } 
        split /\s+\.+\s*/, 
        do { undef $/; scalar <> };

print qq|@data|;

exit 0;
$ perl script.pl infile
03:40   Geonetric File from         CCL                         Complete    03:40:59 03:41:08 00:00:09 00:00:01    N/A
                   005  sys_runccl                                         Complete    03:41:00 03:41:08 00:00:08 00:00:01    N/A
                        Bat:  edtat_2
                        Out:
                        Evt:  Operations - Complete
                   010  sys_osscript                                       Complete    03:41:08 03:41:08 00:00:00 00:00:00    N/A
                        Bat:  
                        Evt:  Operations - Complete
                        Tz :  America/New_York
....................................................................................................
04:00   Geonetric File from                                        Complete    04:00:00 04:00:06 00:00:06 00:00:01    N/A
                   005  sys_runccl                                         Complete    04:00:00 04:00:06 00:00:06 00:00:01    N/A
                        Bat:  edtat_2
                        Out:
                        Evt:  Operations - Complete
                   010  sys_osscript                                       Complete    04:00:06 04:00:06 00:00:00 00:00:00    N/A
                        Bat:  /geonetrics_ftp.ksh
                        Evt:  Operations - Complete
                        Tz :  America/New_York
....................................................................................................
07:00   Rad Provider Copy                                         Complete    07:00:09 07:00:15 00:00:06 00:00:43    N/A
                   005  cp_process_dist                                    Complete    07:00:09 07:00:15 00:00:06 00:00:43    N/A
                        Bat:  HRMC Rad Provider Copy
                        Out:
                        Evt:  Operations - Zero
....................................................................................................
06:58   Radiology Cancer Care                                     Complete    06:58:09 06:58:28 00:00:19 00:03:13    N/A
                   005  cp_process_dist                                    Complete    06:58:09 06:58:28 00:00:19 00:03:13    N/A
                        Bat:  SGAH Radiology Cancer Care
                        Out:
                        Evt:  Operations - Complete
....................................................................................................
04:15   Downtime Comp Rounds List                                 Complete    04:15:01 04:23:21 00:08:20 00:08:43    N/A
                   010  sys_runccl                                         Complete    04:15:01 04:22:26 00:07:25 00:06:01    N/A
                        Bat:  
                        Out: