jbrajkovich
asked on
unix sort question
I have the folllowing data. I need to sort the date time field(1) and the job number last field and write to an ouput file, but I only want to sort the time field on the lines that have the "START" word
Input file:
22:54:42:444 ZEKE JOB START: job U1KC555
22:54:42:647 ZEKE JOB START: job U1KC000
22:54:43:647 ZEKE JOB EOJ: job U1KC555
22:54:43:647 ZEKE JOB START: job U1KC111
22:54:44:647 ZEKE JOB EOJ: job U1KC000
22:54:44:649 ZEKE JOB START: job U1KC999
22:54:45:647 ZEKE JOB EOJ: job U1KC111
output:
22:54:42:444 ZEKE JOB START: job U1KC555
22:54:43:647 ZEKE JOB EOJ: job U1KC555
22:54:42:647 ZEKE JOB START: job U1KC000
22:54:44:647 ZEKE JOB EOJ: job U1KC000
22:54:43:647 ZEKE JOB START: job U1KC111
22:54:45:647 ZEKE JOB EOJ: job U1KC111
22:54:44:649 ZEKE JOB START: job U1KC999
So I'm trying to get the start and end of the jobs listed above and below each other, but I need to sort only on the START jobs
Input file:
22:54:42:444 ZEKE JOB START: job U1KC555
22:54:42:647 ZEKE JOB START: job U1KC000
22:54:43:647 ZEKE JOB EOJ: job U1KC555
22:54:43:647 ZEKE JOB START: job U1KC111
22:54:44:647 ZEKE JOB EOJ: job U1KC000
22:54:44:649 ZEKE JOB START: job U1KC999
22:54:45:647 ZEKE JOB EOJ: job U1KC111
output:
22:54:42:444 ZEKE JOB START: job U1KC555
22:54:43:647 ZEKE JOB EOJ: job U1KC555
22:54:42:647 ZEKE JOB START: job U1KC000
22:54:44:647 ZEKE JOB EOJ: job U1KC000
22:54:43:647 ZEKE JOB START: job U1KC111
22:54:45:647 ZEKE JOB EOJ: job U1KC111
22:54:44:649 ZEKE JOB START: job U1KC999
So I'm trying to get the start and end of the jobs listed above and below each other, but I need to sort only on the START jobs
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would make a bash or tcl script, I am sure someone who is good with perl would use that. Basically read the file one line at a time and if it is an end record read the next line. If it is a start record, output that, and look below this record one line at a time until you see an end record with a matching job id. output this record. Go on to the next record in the file.
Since the data seems to only have hours and seconds, will the files be limited by day in some way? It looks like the records are always in order of occurrence, do you really need to sort the data by time?
Will the job IDs always be unique? Are there only start and stop records? Is there a limit to how many lines will be in the file? The last question determines whether to load the file into memory or to use a temp file.