title: "tail -f <file>" piped to "grep -m1" is not exiting on first match
body: <p>Say I have this file content:</p>
  
  <pre><code>  1 lots
    2 of
    3 content
    4 above
    5
    6 My match string
    7 =======================
    8
    9 other
   10 content
   11 below
  </code></pre>
  
  <p>I want line number of "My match string".</p>
  
  <p>There are some facts:
  (1). Match string occurs only once in the file.
  (2). File may not exist when running my script.
  (3). The file may be really huge that it's generation takes time, and this line gets written only after a few seconds after generation.</p>
  
  <p>My bash script MUST contain a command to generate file followed by finding the above mentioned line number:</p>
  
  <p>My script looks like this:</p>
  
  <pre><code>&lt;command to generate file&gt;
  if file exists 
      tail -f -n +1 my_log_file | grep "My match string" -nm1
  </code></pre>
  
  <p>For big files which take time for generation, this command works.
  tail -f keeps piping content to grep and once this match string gets written to file, -m1 makes grep exit successfully (i.e on first match).</p>
  
  <p>But for small files, grep matches correctly and prints the match, but doesn't come out till I press ctrl+c </p>
  
  <p>Why is this difference in behavior, any idea how fix this?
  Thanks</p>