title: Is there a bug in "zgrep -H"?
body: <p>Just tried grep and zgrep on following test file:</p>
  
  <pre><code>[user@host:~]$ cat /tmp/test
  2015-07-16 14:01:24 aaaa
  2015-07-16 14:02:57 bbbb
  </code></pre>
  
  <p>I also need the file-name printed, so I've added the <code>-H</code> switch and stepped on the following problem:</p>
  
  <pre><code>[user@host:~]$ grep aaaa -A1 -H /tmp/test
  /tmp/test:2015-07-16 14:01:24 aaaa
  /tmp/test-2015-07-16 14:02:57 bbbb
  [user@host:~]$ zgrep aaaa -A1 -H /tmp/test
  /tmp/test:2015-07-16 14:01:24 aaaa
  /tmp/test:02:57 bbbb
  [user@host:~]$ zgrep aaaa -A1 /tmp/test -H
  /tmp/test:2015-07-16 14:01:24 aaaa
  /tmp/test:2015-07-16 14:02:57 bbbb
  </code></pre>
  
  <p>E.g. depending on POSITION of <code>-H</code> switch in the command-line - the behavior is different for me and the issue always reproduces :(</p>
  
  <p>One more test:</p>
  
  <pre><code>[user@host:~]$ gzip /tmp/test
  [user@host:~]$ zgrep aaaa -A1 -H /tmp/test.gz
  /tmp/test.gz:2015-07-16 14:01:24 aaaa
  /tmp/test.gz:02:57 bbbb
  [user@host:~]$ zgrep aaaa -A1 /tmp/test.gz -H
  /tmp/test.gz:2015-07-16 14:01:24 aaaa
  /tmp/test.gz:2015-07-16 14:02:57 bbbb
  </code></pre>
  
  <p>Here's the outline of which zgrep I'm using:</p>
  
  <pre><code>[user@host:~]$ ls -l `which zgrep`
  -rwxr-xr-x 3 root root 3121 Jan 14  2010 /usr/bin/zgrep*
  [user@host:~]$ head `which zgrep`
  #!/bin/sh
  
  # zgrep -- a wrapper around a grep program that decompresses files as needed
  # Adapted from a version sent by Charles Levert &lt;charles@comm.polymtl.ca&gt;
  
  # Copyright (C) 1998, 2001, 2002 Free Software Foundation
  # Copyright (C) 1993 Jean-loup Gailly
  
  # This program is free software; you can redistribute it and/or modify
  # it under the terms of the GNU General Public License as published by
  </code></pre>
  
  <p>Any clue of if it's a known bug or am I doing something wrong?
  Any alternatives? (like to invoke regular grep and then somehow prepend it with file-name without complex temporary files or overhead)</p>
  
  <p><strong>Update</strong> (thanks to dimo414's answer):</p>
  
  <p>Tried to upgrade a bit and faced even more subtle problems (so it looks like only latest or specific versions are working properly):</p>
  
  <pre><code>[user@rhel66:~]$ grep --version|head -1
  GNU grep 2.6.3
  [user@rhel66:~]$ zgrep --version|head -1
  zgrep (gzip) 1.3.12
  [user@rhel66:~]$ grep aaaa -A1 -H /tmp/test
  /tmp/test:2015-07-16 14:01:24 aaaa
  /tmp/test-2015-07-16 14:02:57 bbbb
  [user@rhel66:~]$ zgrep aaaa -A1 -H /tmp/test
  gzip: -A1.gz: No such file or directory
  gzip: -H.gz: No such file or directory
  /tmp/test:2015-07-16 14:01:24 aaaa
  [user@rhel66:~]$ zgrep aaaa -A1 /tmp/test -H
  gzip: -A1.gz: No such file or directory
  /tmp/test:2015-07-16 14:01:24 aaaa
  gzip: -H.gz: No such file or directory
  </code></pre>