Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think this is an appropriate task for a regex. It is clearer to read through the file and accumulate the information you require line by line.</p> <p>This is a Perl solution that uses the sample data you provided.</p> <pre class="lang-perl prettyprint-override"><code>use strict; use warnings; my $info; while (&lt;DATA&gt;) { $info = '' if /Name :/; $info .= $_; print $info if /FAILED to INSERT/; } __DATA__ Name : ... INSERT INTO (...) Values (...) Name : ... &lt;--- These are the lines I need INSERT INTO (...) Values (...) &lt;--- &lt;span style='color:red;'&gt;FAILED to INSERT ...&lt;/span&gt; Name : ... INSERT INTO (...) Values (...) ... </code></pre> <p><strong>output</strong></p> <pre class="lang-none prettyprint-override"><code>Name : ... &lt;--- These are the lines I need INSERT INTO (...) Values (...) &lt;--- &lt;span style='color:red;'&gt;FAILED to INSERT ...&lt;/span&gt; </code></pre> <p>I hope it's clear how to read the data from a file instead. If you pass the file name on the command line then you can just change the loop to <code>while (&lt;&gt;) { ... }</code>.</p> <hr> <p><strong>Edit</strong></p> <p>For a one-line command solution, how about this</p> <pre><code>perl -0777 -ne"/FAILED to INSERT/ and print for split /(?=Name :)/" myfile </code></pre> <p><strong>output</strong> </p> <pre><code>Name : ... &lt;--- These are the lines I need INSERT INTO (...) Values (...) &lt;--- &lt;span style='color:red;'&gt;FAILED to INSERT ...&lt;/span&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload