GNU bug report logs - #70511
Option to grep into compressed files

Previous Next

Package: grep;

Reported by: Mary <marycada <at> proton.me>

Date: Mon, 22 Apr 2024 06:52:04 UTC

Severity: normal

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mary <marycada <at> proton.me>
To: "bug-grep <at> gnu.org" <bug-grep <at> gnu.org>
Subject: Option to grep into compressed files
Date: Sun, 21 Apr 2024 16:46:17 +0000
Hello,

I added an option to grep that filters files through a specified program. The main purpose for that is to uncompress files using the zcat (or `gzip -d`) command, or an equivalent for another compression format.

It works like this:

    grep -j zcat pattern textfile.gz [textfile2.gz...]

(I chose `-j` for no particular reason. Any unused letter could go there.)

This will spawn a shell and execute the given command (zcat), which will receive each file through stdin and its stdout will be used in lieu of the file. Any valid shell command can be used instead of zcat.

This is better than the zgrep commands provided by the gzip, bzip2 and xz projects, because it supports all of the options, including `-r`.

It can also be used with arbitrary commands, like less popular compression algorithms or even commands unrelated to compression. I read at https://www.gnu.org/software/grep/devel.html that there were plans to add `-Z` and `-J` options for gzip and bzip2; my implementation can support any algorithm.

The problem I see with that though is that it would add a shell command option to grep. This is longer to type our than `-Z` or `-J`, but it also provides a shell access to anybody who can control what options grep receives. In practice, I'm not sure how serious that is, but I thought it would be useful to point it out.

I have a patch that I can send. I believe my patch is trivial, the only part that's longer than 3 lines is a simple fork-exec pattern (40 lines including whitespace, but they're the same you've seen in plenty of other programs). I know there are specific requirements regarding copyright, and I don't want to cause problems about that (I can't sign the FSF's documents). May I send my patch?

-- Mary

PS- This is my first time using a mailing list, please let me know if I'm doing something wrong!




This bug report was last modified 1 year and 39 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.