0

With two files with

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?

I would like to search for one term and exclude the other pattern. Is it possible in one command?

I'm using ag because it digging into log.gz files. So I can use zgrep or ag -z.

2
  • 1
    according to the man page, the command line is ag [options] pattern [path ...]. That implies only one pattern. Have you tried ag '\/call_me_maybe' | ag -v '\?param or even ag '\/call_me_maybe' | grep -v '\?param? Commented Jan 17, 2018 at 14:21
  • I finally did your second option. Commented Jan 17, 2018 at 14:23

1 Answer 1

1

I don't use ag but according to the man page, the command line is:

ag [options] pattern [path ...]

That implies only one pattern is allowed.

Just as with grep when you want to combine a search with an inverted search (i.e. perform a search for a AND NOT b), you can pipe the output into grep -v .... e.g.

ag '\/call_me_maybe' | grep -v '\?param'

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.