Thanks for this. It works fine. However, I need all lines matched with the reqid, which includes the line with the reqid and a select, and the 3 lines in the log file after a line with a select. This constitutes all data for a reqid in the log file and I need them to be output together in the order they are in the log file. Apologies, I didn't explain this very well originally.