title: Print file name in front of grep matched pattern output lines
body: <p>I want to print line content of a matched pattern from a input file to a output file. I am using:</p>
  
  <pre><code>    grep -hnr "pattern" ./input.txt &gt; output.txt 
  
  </code></pre>
  
  <p>Output.txt file is like:</p>
  
  <pre><code>this line has the word pattern in it 
  
  </code></pre>
  
  <p>But I want to print name of the input file in the same line in output file. For example,  I want the output file to be like:</p>
  
  <pre><code>input this line has the word pattern in it 
  </code></pre>
  
  <p>If the pattern matches multiple times in input file, I want to print filenames multiple times. For example:</p>
  
  <pre><code>input this line has the word pattern in it 
  input this line also has same pattern
  </code></pre>
  
  <p>and finally, I want to do this in a directory with many input files (*.txt format) and generate one output.txt files with all results.</p>