Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux “中是否有错误?”;zgrep-H“是什么;?_Linux_Bash_Shell_Grep - Fatal编程技术网

Linux “中是否有错误?”;zgrep-H“是什么;?

Linux “中是否有错误?”;zgrep-H“是什么;?,linux,bash,shell,grep,Linux,Bash,Shell,Grep,刚刚在以下测试文件上尝试了grep和zgrep: [user@host:~]$ cat /tmp/test 2015-07-16 14:01:24 aaaa 2015-07-16 14:02:57 bbbb 我还需要打印文件名,因此我添加了-H开关并解决了以下问题: [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 [us

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

[user@host:~]$ cat /tmp/test
2015-07-16 14:01:24 aaaa
2015-07-16 14:02:57 bbbb
我还需要打印文件名,因此我添加了
-H
开关并解决了以下问题:

[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
开关在命令行中的位置,我的行为不同,问题始终会重现:(

还有一个测试:

[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的概要:

[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 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
和/或
zgrep
。在我的机器上,
zgrep--version
的输出会很有帮助,它是:

$ 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.
$grep--版本
grep(GNU grep)2.16
版权所有(C)2014免费软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本。
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,不存在任何担保。
由Mike Haertel和其他人撰写,请参见。
$zgrep--版本
zgrep(gzip)1.6
版权所有(C)2010-2013年自由软件基金会。
这是免费软件。您可以根据
GNU通用公共许可证。
在法律允许的范围内,不存在任何担保。
由吉恩·洛普·盖利撰写。

什么zgrep版本?我记得旧版本不可用。谢谢,那是旧的遗留系统。我会仔细研究一下修复的内容:)我的版本是
grep(GNU grep)2.5.1
gzip 1.3.5
zgrep
不接受
--version
arg(与
--help
-v
相同),我不知道他们在新版本中添加了
--version
支持,再次感谢!在从RHEL5.6切换到CentOS6.6后,我更新了我的问题的详细信息-看起来只有最新(或某些特定)版本工作正常,因此我将尝试使用您在回答中引用的版本:)
$ 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.