Link to home
Start Free TrialLog in
Avatar of jbrajkovich
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
Avatar of lanboyo
lanboyo

Maybe someone can roll this into an awk one liner, but it seems like a non trivial problem.

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.
ASKER CERTIFIED SOLUTION
Avatar of jbrajkovich
jbrajkovich

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial