I have a text file (basically an error log with date, timestamp and some data) in the following pattern:
mm/dd/yy 12:00:00:0001
This is line 1
This is line 2
mm/dd/yy 12:00:00:0004
This is line 3
This is line 4
This is line 5
mm/dd/yy 12:00:00:0004
This is line 6
This is line 7
I'm new at Perl and need to write a script that searches the file for timestamps and merges the data that have the same timestamp in it.
I'm expecting the following output for the above sample.
mm/dd/yy 12:00:00:0001
This is line 1
This is line 2
mm/dd/yy 12:00:00:0004
This is line 3
This is line 4
This is line 5
This is line 6
This is line 7
What's the best way to get this done?
Best Solution
I've had to do this task before on some very large files and the timestamps did not come in order. I didn't want to store it all in memory. I accomplished the task by using a three-pass solution:
This was fast enough for my task where I could let it run while I went for a cup of coffee, but you might have to do something more fancy if you need the results really quickly.