title: Speed up searching a large file using sed or an alternative
body: <p>I have several large files in which I need to find a specific string and take everything between the line which contains the string and the next date at the beginning of a line. This file looks like this:</p>
  <pre><code>20220520-11:53:01.242: foofoobar
  20220520-11:53:01.244: foo_bar blah: this_i_need
  what 
  to 
  do
  20220520-11:53:01.257: blablabla
  20220520-11:53:01.257: bla this_i_need bla
  20220520-11:53:01.258: barbarfooo
  </code></pre>
  <p>The output I need is this:</p>
  <pre><code>20220520-11:53:01.244: foo_bar blah: this_i_need
  what 
  to 
  do
  20220520-11:53:01.257: bla this_i_need bla
  </code></pre>
  <p>Now I'm using <code>sed '/'&quot;$string&quot;'/,/'&quot;$date&quot;'/!d'</code> which works as intended except it also takes the next row with the date even if it doesn't contain the string, but it's not a big problem.</p>
  <p>The problem is that it takes a really long time searching the files.
  Is it possible to edit the <code>sed</code> command so it will run faster or is there any other option to get a better runtime? Maybe using awk or grep?</p>
  <p>EDIT: I forgot to add that the expected results occur multiple times in one file, so exiting after one match is not suitable. I am looping trough multiple files in a for loop with the same $string and same $date. There are a lot of factors slowing the script down that i can't change (extracting files one by one from a 7z, searching and removing them after search in one loop).</p>