Is it possible to print matching file and line number but omit the match? #2746
-
So, I want to print something like: resources/public/externaljs/video.js:21914
resources/public/externaljs/video.js:21915
resources/public/externaljs/video.js:21916 The closest thing I managed to write is: rg --no-column --line-number --no-heading --only-matching --replace= attrs
resources/public/externaljs/video.js:21914:
resources/public/externaljs/video.js:21915:
resources/public/externaljs/video.js:21916: I'm happy with this as it is, but there's any flag I could use to erase that last semicolon? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Nope. I'd probably just throw a If you're reading this data into some other program, you might also be interested in the |
Beta Was this translation helpful? Give feedback.
-
Gotcha, thanks!!
…On Sat, Mar 2, 2024, 8:08 AM Andrew Gallant ***@***.***> wrote:
Nope. I'd probably just throw a sed 's/:$//' at the end of it and call it
good enough.
If you're reading this data into some other program, you might also be
interested in the --json flag.
—
Reply to this email directly, view it on GitHub
<#2746 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPEYKLWJPY63S6RJISALWLYWGXJLAVCNFSM6AAAAABECYSYSOVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DMNJRGAYTC>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hey there, I had the same question and I have been searching for the answer in discussion for few weeks now from time to time. The reason this is important to me is because some editor primarily helix allows you to open files by number and columns extended to it. hx boilerplate.py:19:12 I tried getting similar answers with grep as well and found the following result. The above doesn't solve my problem either, given they also append the query next to the search line number. $ grep -Horn python
boilerplate.py:1:python
boilerplate.py.txt:1:python I was looking for the search results filtered by line only. The solution suggested above works good. $ rg --no-column --line-number --no-heading --only-matching --replace= python | sed 's/:$//'
testdata/with_config/pass.py:1
testdata/with_config/fail.py:1 And now I can open all the match using the following command. rg --no-column --line-number --no-heading --only-matching --replace= python | sed 's/:$//' | xargs hx But this is too long. I wonder it there's a more simpler way to achieve the same. As of now, I trimmed it down to something like using short flags. $ rg -r= -o -n --no-heading --no-column python |
Beta Was this translation helpful? Give feedback.
Nope. I'd probably just throw a
sed 's/:$//'
at the end of it and call it good enough.If you're reading this data into some other program, you might also be interested in the
--json
flag.