TryFor saving colors to a file, try adding --color always:
pdfgrep --color always "$author" *.pdf > output_fileoutput.txt
Then you can cat the file and it'll still be bold and red where you need it.
For convertingIf for some reason you have a version of pdfgrep that doesn’t have these options (or you came here because you’re using a different program), you can instead put script -q /dev/null in front of the command to RTFmake a “fake” terminal:
script -q /dev/null pdfgrep "$author" *.pdf > output.txt
For converting to RTF, ansifilter is working pretty well for me:
pdfgrep --color always "$author" *.pdf | ansifilter --rtf > output.rtf
Basically, how this works is that pdfgrep writes some non-printing ANSI color codes. Red text starts with \e[0;31m and you can reset colors and formatting with \e[0m, so writing with red text looks like:
echo $'here is \e[0;31mred text\e[0m' # the $ makes it interpret `\e` sequences
But pdfgrep knows whether it's in a terminal that supports printing colors, so by default it will only insert these characters when they will do anything. You can override it with --color always.