3

I am using rg (or alternatively ag) to search for occurrences of a string in a folder with many files, like this:

$ rg "cat"
lolo
3:cat

lala
2:cat

Now I would like to get rid of these matches.

How can I remove each line containing a match from every file with matches?

luochen1990
  • 3,689
  • 1
  • 22
  • 37
TTT
  • 6,505
  • 10
  • 56
  • 82
  • I wouldn't use `rg` for this in the first place. Write a small script which is given a file, and if this contains such a line in question, replaces the file by a new one with those lines deleted. Then use `find` to traverse your file tree and apply you script to each file. – user1934428 Feb 27 '20 at 09:37
  • This is job for `awk` or `sed`, our venerated text-processing tools! See – Quasímodo Feb 27 '20 at 10:20

2 Answers2

2

its rg -v 'pattern'.
Same as that of grep

noel zubin
  • 662
  • 9
  • 11
0

Use -v argument, as example:

rg -v "cat" test.log

Result

1:lolo
3:
4:lala
m0zgen
  • 569
  • 7
  • 20