首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"zgrep -H“中有bug吗?

"zgrep -H“中有bug吗?
EN

Stack Overflow用户
提问于 2015-07-16 17:05:55
回答 1查看 351关注 0票数 1

刚刚在以下测试文件上尝试了grep和zgrep:

代码语言:javascript
复制
[user@host:~]$ cat /tmp/test
2015-07-16 14:01:24 aaaa
2015-07-16 14:02:57 bbbb

我还需要打印文件名,因此我添加了-H开关并处理了以下问题:

代码语言:javascript
复制
[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

例如,根据-H开关在命令行中的位置--我的行为是不同的,问题总是重复:(

再来一次测试:

代码语言:javascript
复制
[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

下面是我使用的zgrep的大纲:

代码语言:javascript
复制
[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 <charles@comm.polymtl.ca>

# 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

知道它是已知的窃听器还是我做错什么了吗?有其他选择吗?(喜欢调用常规grep,然后在不需要复杂临时文件或开销的情况下,用文件名将其添加到前面)

更新(感谢dimo414 414的回答):

试图升级一下,但遇到了更微妙的问题(所以看起来只有最新或特定的版本才能正常工作):

代码语言:javascript
复制
[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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-16 17:14:00

我看不出你描述的错误:

代码语言:javascript
复制
$ grep aaaa -A1 -H /tmp/test
/tmp/test:2015-07-16 14:01:24 aaaa
/tmp/test-2015-07-16 14:02:57 bbbb

$ zgrep aaaa -A1 -H /tmp/test
/tmp/test:2015-07-16 14:01:24 aaaa
/tmp/test:2015-07-16 14:02:57 bbbb

$ zgrep aaaa -A1 /tmp/test -H
/tmp/test:2015-07-16 14:01:24 aaaa
/tmp/test:2015-07-16 14:02:57 bbbb

这可能是一个已知的修复错误,您正在运行一个旧版本的grep和/或zgrepzgrep --version的输出将很有帮助,在我的机器上它是:

代码语言:javascript
复制
$ grep --version
grep (GNU grep) 2.16
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

$ zgrep --version
zgrep (gzip) 1.6
Copyright (C) 2010-2013 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Jean-loup Gailly.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31460433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档