bug-gzip
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: zgrep -<NUM> doesn't work if <NUM> is two digits or greater


From: Jim Meyering
Subject: Re: zgrep -<NUM> doesn't work if <NUM> is two digits or greater
Date: Tue, 07 Aug 2012 10:10:37 +0200

Thomas Bushnell, BSG wrote:
> Create a gzipped file:
>
>    $ for i in $(seq 1 100); do echo $i; done > file.txt
>    $ gzip file.txt
>
> Then:
>
>    $ zgrep -9 17 file.txt.gz
>    8
>    9
>    ...
>    25
>    26
>
> works.  But:
>
>    $ zgrep -10 17 file.txt.gz
>    gzip: 17.gz: No such file or directory
>
> fails.
>
> Note that "grep -9 17 file.txt" and "grep -10 17 file.txt" work just
> fine.
>
> (https://bugs.launchpad.net/bugs/1032831)
>
> Please include me in the CC on any replies.

Hi Thomas,

Thanks for the report.
That made a nice puzzle to go with my morning caffeine ;-)

Here's the fix:
I'll write the NEWS entry and test later.

diff --git a/zgrep.in b/zgrep.in
index d09bfa7..abc5847 100644
--- a/zgrep.in
+++ b/zgrep.in
@@ -66,9 +66,13 @@ while test $# -ne 0; do

   case $option in
   (-[0123456789EFGHIKLPRTUVZabchilnoqrsuvwxyz]?*)
-    arg2=-\'$(expr "X$option" : 'X-.[0-9]*\(.*\)' | sed "$escape")
-    eval "set -- $arg2 "'${1+"$@"}'
-    option=$(expr "X$option" : 'X\(-.[0-9]*\)');;
+    if expr "X$option" : 'X-[0-9]\+$' > /dev/null; then
+      : # Let a multi-digit, digit-only option like -10 fall through.
+    else
+      arg2=-\'$(expr "X$option" : 'X-.[0-9]*\(.*\)' | sed "$escape")
+      eval "set -- $arg2 "'${1+"$@"}'
+      option=$(expr "X$option" : 'X\(-.[0-9]*\)')
+    fi;;
   (--binary-*=* | --[lm]a*=* | --reg*=*)
     ;;
   (-[ABCDXdefm] | binary-* | --file | --[lm]a* | --reg*)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]