title: How to print a line along with its matching pattern using grep
body: <p>I want to print the matched string along with the matched line using grep or awk or sed, preferable grep as I want to do it on a huge file and grep gives me the best times.</p>
  
  <p>For eg:
  If I want to match 'hello'
  then using the command: <code>grep 'hello' filename</code> , I get the result : <code>echo hello World</code></p>
  
  <p>Using the command: <code>grep -o 'hello' filename</code>, I can get the result : </p>
  
  <pre><code>hello
  </code></pre>
  
  <p>Anyway I can get the result :</p>
  
  <pre><code>echo hello World , hello
  </code></pre>
  
  <p>or similar to this.
  Help would be appreciated</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>hello is just an example, it can be a variable too taken from a file, hence it is not static, if we have multiple matching then all of them should be appended.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>As an example to the earlier edit, consider a file <em>keywords</em> which has contents </p>
  
  <pre><code>hello
  why
  </code></pre>
  
  <p>and we have another file on which we would be checking these keywords <em>testfile</em> which has contents</p>
  
  <pre><code>this line contains hello world
  this line contains why hello world
  </code></pre>
  
  <p>so when we run grep, we can get the answer like :</p>
  
  <p><strong>Description|regex(tagged for grep result),</strong></p>
  
  <pre><code>this line contains hello world|hello
  this line contains why hello world|hello,why 
  </code></pre>