Skip to main content
added 332 characters in body
Source Link
Eric Renouf
  • 18.7k
  • 7
  • 51
  • 66

You could do that with process substitution as follows:

grep -f <(awk '{print $1 "\n" $3}' filename) otherfile

This will have grep read its patterns from a file (the -f flag), which in this case is actually the output of the process awk...filename which prints the patterns one per line. Then grep searchs for those patterns in otherfile

Though perhaps less efficient if you really want to do it in a pipeline you could do it with grep reading its patterns from stdin like

awk '{print $1 "\n" $3}' filename | grep -f - otherfile

Edit: seeing your question's edit about using grep and then awk, you can let awk do the pattern match for you by doing:

grep -Ff <(awk '/pattern/ {print $1 "\n" $3}' <(pdftotext 'filename.pdf' -)) otherfile

or as a pipeline:

pdftotext 'filename.pdf' - | awk '/pattern/ {print $1 "\n" $3}' | grep -Ff - otherfile

You could do that with process substitution as follows:

grep -f <(awk '{print $1 "\n" $3}' filename) otherfile

This will have grep read its patterns from a file (the -f flag), which in this case is actually the output of the process awk...filename which prints the patterns one per line. Then grep searchs for those patterns in otherfile

Though perhaps less efficient if you really want to do it in a pipeline you could do it with grep reading its patterns from stdin like

awk '{print $1 "\n" $3}' filename | grep -f - otherfile

You could do that with process substitution as follows:

grep -f <(awk '{print $1 "\n" $3}' filename) otherfile

This will have grep read its patterns from a file (the -f flag), which in this case is actually the output of the process awk...filename which prints the patterns one per line. Then grep searchs for those patterns in otherfile

Though perhaps less efficient if you really want to do it in a pipeline you could do it with grep reading its patterns from stdin like

awk '{print $1 "\n" $3}' filename | grep -f - otherfile

Edit: seeing your question's edit about using grep and then awk, you can let awk do the pattern match for you by doing:

grep -Ff <(awk '/pattern/ {print $1 "\n" $3}' <(pdftotext 'filename.pdf' -)) otherfile

or as a pipeline:

pdftotext 'filename.pdf' - | awk '/pattern/ {print $1 "\n" $3}' | grep -Ff - otherfile
Source Link
Eric Renouf
  • 18.7k
  • 7
  • 51
  • 66

You could do that with process substitution as follows:

grep -f <(awk '{print $1 "\n" $3}' filename) otherfile

This will have grep read its patterns from a file (the -f flag), which in this case is actually the output of the process awk...filename which prints the patterns one per line. Then grep searchs for those patterns in otherfile

Though perhaps less efficient if you really want to do it in a pipeline you could do it with grep reading its patterns from stdin like

awk '{print $1 "\n" $3}' filename | grep -f - otherfile