Sort by Duration


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort by Duration
# 1  
Old 12-04-2012
Sort by Duration

HTML Code:
        ..........................................................................................................................         
           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.

Last edited by Daniel Gate; 12-04-2012 at 05:28 PM..
# 2  
Old 12-04-2012
Where is that? I see several things in each entry which could qualify...
# 3  
Old 12-04-2012
HTML Code:
  ..........................................................................................................................
         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 ----------

PHP Code:
 ..........................................................................................................................
         
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
# 4  
Old 12-04-2012
You may need GNU awk for this:

Code:
# 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

# 5  
Old 12-05-2012
PHP Code:
        ..........................................................................................................................
                                              
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 (BillFile                                    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.
# 6  
Old 12-05-2012
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?
# 7  
Old 12-05-2012
I am on AIX 6.1. It is a long file, so there might be cr somewhere ....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to calculate time duration in Linux?

I want to calculate duration for below file in this format SID | Date | Starttime |Date |End time 1607 |2019-04-05|13:06:42|2019-04-05|13:07:12 2327 |2019-04-05|13:57:26|2019-04-05|13:57:43 O/p should be like this: SID | Date | Starttime |Date |Endtime... (4 Replies)
Discussion started by: anupmishra
4 Replies

2. Shell Programming and Scripting

Function to get the duration of all videos in a folder(s)

did this function to generate the duration of all the video files in a folder or multiple folders, it works fine for my use (I am no Guru as you may have noticed) but when I give it a lot of folders the calculation get a bit borked. If any good soul had the energy to look at it and give... (4 Replies)
Discussion started by: zouhair
4 Replies

3. Shell Programming and Scripting

Duration Calculation

I have 2 variables startTime='122717 23:20' endTime='122817 0:40' how can i get the elapsed duration as like "1 hour 20 minutes" ? (8 Replies)
Discussion started by: vikram3.r
8 Replies

4. Shell Programming and Scripting

Need help in Inix script for finding duration

I have a file with time in it. I need to find the duration between the timestamp by subtracting second row from third row and so on. and wherever it is more than 30 minutes it should display start and end time which have been subtracted file : 00:44:11 00:44:11 00:44:13 00:44:13 00:46:51... (2 Replies)
Discussion started by: Muskaan
2 Replies

5. UNIX for Beginners Questions & Answers

Process duration

Hi , How can I check that for a single process, for example pagent for how much duration this process was up or down and also I need multiple entries if this process was down or up multiple times. Please help. (3 Replies)
Discussion started by: Ashish Garg
3 Replies

6. UNIX Desktop Questions & Answers

arecord not interrupted after specified duration

I have used the arecord command like this arecord -d 1 test.wav It is keep on waiting. I need to manually interrupt it by ctrl-c. Why it is not interrupting after one second? The arecord version which I am using is : arecord: version 1.0.23 by Jaroslav Kysela (3 Replies)
Discussion started by: thillai_selvan
3 Replies

7. UNIX for Dummies Questions & Answers

Copy duration of cp

Hello forum, i would like to ask if there's a way to view the remaining time of copying files (talking about copying gigabytes) while the cp commnad is running. I'm using OpenBSD 4.9 -stable. Thanx in advance. :) (2 Replies)
Discussion started by: sepuku
2 Replies

8. Solaris

ufsdump backup duration

hi, i'm trying to figure out how to tell the amount of time a ufsdump of a directory takes. i use the below command: echo "Starting Backup of u4" >> /backup/backup.log 2>&1 /usr/sbin/ufsdump 0uf /dev/rmt/0n /u4 >> /backup/backup.log 2>&1 echo "Finished Backup of u4" >> /backup/backup.log... (0 Replies)
Discussion started by: pinoy43v3r
0 Replies

9. Shell Programming and Scripting

duration calculation

I have a file which has 3 coloumns emp_name, Joining_date, Designation. abc 12/1/2001 SSE def 2/25/2007 SE ghi 3/18/2009 SA abc 8/1/2008 SSE def 2/13/2007 SE ghi 3/24/2005 SA I need to find out the emp who has been in the company for longest period(Till date). Can I have any... (3 Replies)
Discussion started by: siba.s.nayak
3 Replies

10. Shell Programming and Scripting

date duration fail to calculate

Hi Everyone, I was very sad after a long way but still cannot figure out the duration between two date. $date1="20090812 23:48:56"; $date2="20090813 00:01:37"; The output will be "001241". I did the following tries, like print localtime(UnixDate(ParseDate("20090812 23:48:56"),"%s"));... (2 Replies)
Discussion started by: jimmy_y
2 Replies
Login or Register to Ask a Question