gpt4 book ai didi

linux - "zgrep -H"有错误吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:51:03 29 4
gpt4 key购买 nike

刚刚在以下测试文件上尝试了 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 开关的 POSITION - 行为对我来说是不同的,问题总是重现 :(

再进行一次测试:

[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,然后以某种方式在其前面加上文件名,而无需复杂的临时文件或开销)

更新(感谢dimo414的回答):

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

[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

最佳答案

我没有看到您描述的错误:

$ 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 的输出会很有帮助,在我的机器上是:

$ 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.

关于linux - "zgrep -H"有错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460433/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com