ripgrep icon indicating copy to clipboard operation
ripgrep copied to clipboard

Flag for dedicated file output on searches

Open 0xjmux opened this issue 2 years ago • 1 comments

Describe your feature request

I use rg to search extremely large directories (>1TB), and the output can get a bit long (several thousand lines, in some cases). I would like a way to see the colored, pretty output in the terminal, and also save the search results to a file in case an issue or really long line is run into that completely takes up the viewable terminal history.

Something like

rg --output-file outputFile.txt searchText

Would output the usual, pretty output to stdout, but also save the results of the search in a readable format to out.txt.

I am well aware of things like tee -a that allow for output to stdout and to a file, but using it results in either A) bash color formatting in the file and the ruining of viewability in vim or B) difficult to read output in the terminal.

The features present in programs like youtube-dl and nmap are close to what i'm looking for.

Thanks, and thanks for creating such an awesome search tool!

0xjmux avatar Mar 20 '22 00:03 0xjmux

In terms of implementation, in theory, it should not be too difficult to implement. I think the strategy I would take is to provide a tee-like implementation in ripgrep core of the termcolor::WriteColor trait. It would do the standard stuff for writing with color support, but would also provide a way to be built with a file that it would also write to (but without color support).

But I'm not quite convinced that this is worth adding. This seems like a very niche issue and could be solved relatively easily on your end with a tool that strips color formatting from the file you've written with tee. See: https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream

BurntSushi avatar Mar 21 '22 12:03 BurntSushi

relates to #2371

rwese avatar Oct 25 '23 09:10 rwese

Duplicate of #2371. (I know this issue was created first, but I think #2371 ended up containing more info.)

BurntSushi avatar Nov 22 '23 21:11 BurntSushi