Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

So I want to use grep to list the filenames of pdfs that match the search string "Type 1C".

grep is supposed to get the data from pdffonts, but when I execute this syntax it just executes pdffonts normally.

find . -type f -iname "*.pdf" -print0 -exec pdffonts {} \; |xargs -0 grep -c -l "Type 1C"

When I add - after {} I get the help file of pdffonts, which must mean it doesn't support this argument.

But how can I pipe pdffonts to grep then?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

There's are '-----------------------' included in the output stream and it gets interpreted as a command switch which messes everything up. So, remove those pesky dashes using tr before continuing the pipeline.

find . -type f -iname "*.pdf"  -print0 -exec pdffonts {} \; | tr -d '-' | xargs -0 | grep 'Type 1'
HelveticaNeueLight                  Type 1            yes no  no      18  0
HelveticaNeueRoman                  Type 1            yes no  no      22  0
HelveticaNeueMedium                 Type 1            yes no  no      26  0
HelveticaNeueLight                  Type 1            yes no  no      18  0
HelveticaNeueRoman                  Type 1            yes no  no      22  0
HelveticaNeueMedium                 Type 1            yes no  no      26  0
HelveticaNeueLight                  Type 1            yes no  no      18  0
HelveticaNeueRoman                  Type 1            yes no  no      22  0
HelveticaNeueMedium                 Type 1            yes no  no      26  0
HelveticaNeueLight                  Type 1            yes no  no      18  0
HelveticaNeueRoman                  Type 1            yes no  no      22  0
HelveticaNeueMedium                 Type 1            yes no  no      26  0

You can't use 'grep -l' because there is no concept of files anymore, all that's coming out of there is a stream of text. If you want to maintain the file list as a index then you will likely end up with a for loop.

share|improve this answer
    
Thank you. I get it now :) I inferred (wrongly) that if grep demands a filename, the Linux command line would be able to take from pdffonts only the filename...instead of outputting the raw data..I assumed wrong. I am new to this. thanks again :) –  Roy Jul 4 '13 at 19:36
    
You're welcome. –  ppetraki Jul 4 '13 at 19:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.