LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How do I print the filename in awk? (https://www.linuxquestions.org/questions/programming-9/how-do-i-print-the-filename-in-awk-687770/)

Disillusionist 12-02-2008 12:02 PM

How do I print the filename in awk?
 
I have an issue where I am trying to find pdf files that contain pdfx: (metadata) in Windows.

I have cygwin installed but grep is giving me the same results for:
Code:

grep 'pdfx:' *.pdf
as for:
Code:

grep -v 'pdfx:' *.pdf
I can find the information in the files using gawk:
Code:

gawk '(/pdfx:/)' *.pdf
However, what I need is the filename.

Is there a way of printing the filename in gawk?

colucix 12-02-2008 12:09 PM

Code:

gawk '/pdfx:/{print FILENAME; nextfile}' *.pdf
In awk the built-in variable FILENAME stores the name of the current input file (if any).

Disillusionist 12-02-2008 12:20 PM

Excelent!

Thanks for that it works perfectly.


All times are GMT -5. The time now is 08:32 PM.