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.

  • 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? – cas Jan 17 '18 at 14:21
  • I finally did your second option. – PockPock Jan 17 '18 at 14:23
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'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.