36

I've got a list of files that I would like to search for a pattern with ripgrep.

How can this be done?

1 Answer 1

44

ripgrep accepts file paths as arguments. So just pass your files as arguments:

rg pattern file1 file2 ... 

If your list is in a file, with one path per line, then use xargs:

xargs -d '\n' -a list-file rg pattern 

Or if it's a list generated from find, then:

find ./ ... -print0 | xargs -0 rg pattern 
5
  • 2
    Searching only some specific file can be done like find . -iname '*finde_me*.md' -print0 | xargs -0 rg 'search term' Commented Aug 7, 2020 at 9:41
  • 16
    In that case, you might as well just use rg 'search term' -g '*finde_me*.md' :-) Commented Aug 7, 2020 at 13:17
  • Nice! Started using ripgrep a couple of weeks ago and it's truly amazing! Learning so much! Commented Aug 7, 2020 at 13:31
  • Is there a performance benefit in not using xargs, find, etc? Commented Aug 5, 2022 at 10:00
  • There might be, given that, e.g., find is single threaded and ripgrep is multi-threaded. Why not try both and compare them for your use case? Commented Aug 5, 2022 at 14:08

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.