Skip to main content
Simplified with `--color always`, added option to use `script -q`.
Source Link
wobtax
  • 1.2k
  • 3
  • 17

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.

Try adding --color always:

pdfgrep --color always "$author" *.pdf > output_file.txt

Then you can cat the file and it'll still be bold and red where you need it.

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.

For saving colors to a file, try adding --color always:

pdfgrep --color always "$author" *.pdf > output.txt

Then you can cat the file and it'll still be bold and red where you need it.

If 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 make 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.

Simplified with `--color always`
Source Link
wobtax
  • 1.2k
  • 3
  • 17

Try adding putting script -q /dev/null before your command--color always:

scriptpdfgrep -q /dev/null-color pdfgrepalways "$author" *.pdf > output_file.txt

Then you can cat the file and it'll still be bold and red where you need it.

For converting to RTF, ansifilter is working pretty well for me:

scriptpdfgrep -q /dev/null-color pdfgrepalways "$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.

Try putting script -q /dev/null before your command:

script -q /dev/null pdfgrep "$author" *.pdf > output_file.txt

Then you can cat the file and it'll still be bold and red where you need it.

For converting to RTF, ansifilter is working pretty well for me:

script -q /dev/null pdfgrep "$author" *.pdf | ansifilter --rtf > output.rtf

Try adding --color always:

pdfgrep --color always "$author" *.pdf > output_file.txt

Then you can cat the file and it'll still be bold and red where you need it.

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.

Source Link
wobtax
  • 1.2k
  • 3
  • 17

Try putting script -q /dev/null before your command:

script -q /dev/null pdfgrep "$author" *.pdf > output_file.txt

Then you can cat the file and it'll still be bold and red where you need it.

For converting to RTF, ansifilter is working pretty well for me:

script -q /dev/null pdfgrep "$author" *.pdf | ansifilter --rtf > output.rtf