Is it possible to grep this output from gpg

Take the following command (real example) :

~$ gpg --edit-key foo@bar.net showpref quit
(...)
[ultimate] (1). Foo Bar <foo@bar.net>
     Cipher: AES256, AES192, AES, CAST5, 3DES
     AEAD: 
     Digest: SHA256, SHA1, SHA384, SHA512, SHA224
     Compression: ZLIB, BZIP2, ZIP, Uncompressed
     Features: MDC, AEAD, Keyserver no-modify
     Preferred keyserver: ldap://keyserver.pgp.com
~$

Piping the output into a | grep doesn’t work :

~$ gpg --edit-key foo@bar.net showpref quit | grep Compression
(...)
[ultimate] (1). Foo Bar <foo@bar.net>
     Cipher: AES256, AES192, AES, CAST5, 3DES
     AEAD: 
     Digest: SHA256, SHA1, SHA384, SHA512, SHA224
     Compression: ZLIB, BZIP2, ZIP, Uncompressed
     Features: MDC, AEAD, Keyserver no-modify
     Preferred keyserver: ldap://keyserver.pgp.com
~$

Is there a way to make that work ? E.g., the result I’d like to get is :

~$ gpg --edit-key foo@bar.net showpref quit | grep Compression
     Compression: ZLIB, BZIP2, ZIP, Uncompressed
~$

[EDIT : what I tried so far ] :

@steeldriver, @RomeoNinov : I don’t think redirecting stderr is going to do the trick. It doesn’t look like gpg‘s output goes to stderr.

Basically, gpg is an interactive command, but launching gpg ... cmd1 cmd2 makes it non-interactive (e.g., gpg ... showpref quit is the same as doing interactively showpref followed by quit in gpg‘s shell).

@steeldriver :

~$ gpg --edit-key foo@bar.net showpref quit 2> >(grep Compression)
(...)
[ultimate] (1). Foo Bar <foo@bar.net>
     Cipher: AES256, AES192, AES, CAST5, 3DES
     AEAD: 
     Digest: SHA256, SHA1, SHA384, SHA512, SHA224
     Compression: ZLIB, BZIP2, ZIP, Uncompressed
     Features: MDC, AEAD, Keyserver no-modify
     Preferred keyserver: ldap://keyserver.pgp.com
~$

@RomeoNinov :

~$ gpg --edit-key foo@bar.net showpref quit 2>&1| grep Compression
(...)
[ultimate] (1). Foo Bar <foo@bar.net>
     Cipher: AES256, AES192, AES, CAST5, 3DES
     AEAD: 
     Digest: SHA256, SHA1, SHA384, SHA512, SHA224
     Compression: ZLIB, BZIP2, ZIP, Uncompressed
     Features: MDC, AEAD, Keyserver no-modify
     Preferred keyserver: ldap://keyserver.pgp.com
~$
Asked By: ChennyStar

||

The solution is to use --batch. This will help gpg to send info to standard file handlers.

# gpg  --batch --edit-key user@example.net showpref quit 2>&1 |grep Com
     Compression: ZLIB, BZIP2, ZIP, Uncompressed
Answered By: Romeo Ninov
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.