Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd probably go for John's <code>sed</code> solution but, since you asked about <code>awk</code> as well:</p> <pre><code>$ echo 'Line1: I just want to make clear of the problem Line2: Thanks to all who look into my problem Line3: How to solve the problem? Line4: Thanks to all.' | awk '/^Line2:/{$0=$0" Please help me"}{print}' </code></pre> <p>This outputs:</p> <pre><code>Line1: I just want to make clear of the problem Line2: Thanks to all who look into my problem Please help me Line3: How to solve the problem? Line4: Thanks to all. </code></pre> <p>An explanation as to how it works may be helpful. Think of the <code>awk</code> script as follows with conditions on the left and commands on the right:</p> <pre><code>/^Line2:/ {$0=$0" Please help me"} {print} </code></pre> <p>These two <code>awk</code> clauses are executed for every single line processed.</p> <p>If the line matches the regular expression <code>^Line2:</code> (meaning "Line2:" at the start of the line), you change <code>$0</code> by appending your desired string (<code>$0</code> is the entire line as read into <code>awk</code>).</p> <p>If the line matches the empty condition (all lines will match this), <code>print</code> is executed. This outputs the current line <code>$0</code>.</p> <p>So you can see it's just a simple program which modifies the line where necessary and outputs the line, modified or not.</p> <hr> <p>In addition, you may want to use <code>/^Line2:/</code> as the key even for a <code>sed</code> solution so you don't pick up <code>Line2</code> in the middle of the text or <code>Line20</code> through <code>Line29</code>, <code>Line200</code> through <code>Line299</code> and so on:</p> <pre><code>sed '/^Line2:/s/$/ Please help me/' </code></pre>
 

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