1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ripgrep でマッチしない行を出力する

Last updated at Posted at 2020-01-08

問題

ripgrep という高速に動作する検索コマンドがある。これを使って日常的にソースコードを調べているが、ときどき検索したい文字が、他の文字の部分文字列になっていて、余分な行が出力されてしまうことがある。たとえば unit を検索したいのだが unit_id がたくさんヒットしてしまう、といった事が起こる。

ripgrep では正規表現が有効だが、否定先読みはできない。

解決策

最も簡単な方法は --invert-match (短縮形は -v)を使うこと。たとえば、下記のようにする。

rg unit | rg -v unit_id

ただし、色付けやグルーピングの情報が落ちてしまう。しかも、二つとも登場する行がヒットしなくなってしまう。例えば下記。

unit = unit_id

もっと良い方法があるかもしれない。
ag をインストールしているなら否定先読みができるらしい。 ag を使うべきか。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?