I have a largish file of around 50k lines. I need to enter data from a line into a db only if the next line has a certain word in it. For instance
00:00:01 Request from 1.1.1.1 for A-record for www.website1.com
00:00:01 Sending reply to 1.1.1.1 about A-record for www.website1.com:
00:00:01 -> Answer: A-record for www.website1.com = 999.999.999.999
00:00:02 Request from 1.1.1.1 for A-record for www.website2.com
00:00:02 Plug-in "Domain Blacklist1" matched A-record for www.website2.com
00:00:03 Request from 1.1.1.1 for A-record for www.website3.com
00:00:04 Sending reply to 1.1.1.1 about A-record for www.website3.com:
00:00:01 -> Answer: A-record for www.website3.com = 888.888.888.888
I only want to enter the data from the 4th line because the 5th line has "Domain Blacklist" in it.
Any thoughts on how I might go about that?
Paul
Use File functions to loop through the file, one line at a time. Use a separate variable to keep track of the "previous" line (updating it at the end of each iteration). Within the loop, check the current line for the magic phrase. If it's found, append the previous line variable to a result array. When finished, use the array of lines however you wish.