Skip to content

Is there a way to print out filename and line number separated by colon? #2031

Answered by BurntSushi
rossmacarthur asked this question in Q&A
Discussion options

You must be logged in to vote

Currently the default output shows the filenames and then each case listed underneath.

You can switch to the standard grep output format with --no-heading.

Using rg -l prints out only the line numbers

It does not. It prints matching file paths and the number of matching lines. It prints just the matching file paths. If you combine it with -c/--count, then it also includes the number of matching lines.

but what I would like is something like the following

Well, that's what ripgrep does with the --no-heading flag, with the exception of also printing the matching contents. So you just have to get rid of the matching contents. Here are a few ways to do that, given a query of foo:

# Requ…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@rossmacarthur
Comment options

@BurntSushi
Comment options

@MrBrN197
Comment options

Answer selected by rossmacarthur
Comment options

You must be logged in to vote
1 reply
@BurntSushi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants