有两个文件
echo 'example.com/call_me?param' > file1.txt
echo 'example.com/call_me_maybe?param' >> file1.txt
echo 'example.com/call_me?' >> file1.txt
echo 'example.com/call_me?param' > file2.txt
echo 'example.com/call_me_maybe?' >> file2.txt
$ ag -v '\?param'
file2.txt
2:example.com/call_me_maybe?
file1.txt
3:example.com/call_me?
$ ag '\/call_me_maybe' -v '\?param'
ERR: Error stat()ing: \?param
ERR: Error opening directory \?param: No such file or directory
$ ag '\/call_me_maybe' -v '\?param' file1.txt
ERR: Error stat()ing: \?param
ERR: Error opening directory \?param: No such file or directory
file1.txt
1:example.com/call_me?param
3:example.com/call_me?
我想搜索一个术语并排除其他模式。是否可以用一个命令来实现?
我使用 ag 因为它会挖掘log.gz
文件。所以我可以使用zgrep
or ag -z
。
答案1
我不使用ag
,但根据手册页,命令行是:
ag [options] pattern [path ...]
这意味着只允许一种模式。
正如grep
当您想要将搜索与反向搜索相结合(即执行搜索a AND NOT b
)时,您可以将输出通过管道传输到grep -v ...
。例如
ag '\/call_me_maybe' | grep -v '\?param'