Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to combine the current line and the next line based on a pattern that exists in the next line. (Using awk)
    text
    copied!<p>I have tried countless recommendations in this site for the awk syntax but somehow i cannot get my head around awk..</p> <p>I am trying to combine two lines ( the current one and the next one ) only when my expr exists in the next line. </p> <p>For example I have a text file which contains the following:</p> <pre><code>&lt;option value="1" selected&gt; channel 1 &lt;div id="program_13" class="tree_3"&gt;&lt;input type="checkbox" name="output_checkbox" value="13"&gt;&amp;nbsp; &amp;nbsp;Somename1&lt;/div&gt; &lt;option value="2" selected&gt; channel 2 &lt;div id="program_21" class="tree_3"&gt;&lt;input type="checkbox" name="output_checkbox" value="21"&gt;&amp;nbsp; &amp;nbsp;Someothername&lt;/div&gt; &lt;option value="3" selected&gt; channel 3 &lt;option value="4" selected&gt; channel 4 &lt;option value="5" selected&gt; channel 5 </code></pre> <p>I want to join the current line with the next one only when the "output_checkbox" expression exists within the next line. This may be truth for all OR any of the 5 main lines. </p> <p>On the example above, my desired result would be :</p> <pre><code>&lt;option value="1" selected&gt; channel 1 &lt;div id="program_13" class="tree_3"&gt;&lt;input type="checkbox" name="output_checkbox" value="13"&gt;&amp;nbsp; &amp;nbsp;Somename1&lt;/div&gt; &lt;option value="2" selected&gt; channel 2 &lt;div id="program_21" class="tree_3"&gt;&lt;input type="checkbox" name="output_checkbox" value="21"&gt;&amp;nbsp; &amp;nbsp;Someothername&lt;/div&gt; &lt;option value="3" selected&gt; channel 3 &lt;option value="4" selected&gt; channel 4 &lt;option value="5" selected&gt; channel 5 </code></pre> <p>I am hoping to get the following at the end by using sed (which i think i can handle):</p> <pre><code>channel 1: Somename1 channel 2: Someothername channel 3: channel 4: channel 5: </code></pre> <p>I am looking forward to your suggestions</p>
 

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