LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-02-2008, 01:02 PM   #1
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
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?

Last edited by Disillusionist; 12-02-2008 at 01:03 PM.
 
Old 12-02-2008, 01:09 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
gawk '/pdfx:/{print FILENAME; nextfile}' *.pdf
In awk the built-in variable FILENAME stores the name of the current input file (if any).
 
Old 12-02-2008, 01:20 PM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Original Poster
Rep: Reputation: 83
Excelent!

Thanks for that it works perfectly.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 8 12-18-2013 06:36 PM
How to parameterize which field awk should print? dbland07666 Linux - Newbie 2 10-29-2007 04:49 PM
Using awk to print CLI-version of kaddressbook ? Yalla-One Programming 6 11-05-2006 03:51 PM
awk print lines that doesn't have a pattern huynguye Programming 5 05-04-2006 12:08 PM
Parse a filename with awk and sed chrisk5527 Programming 2 06-08-2004 07:13 PM


All times are GMT -5. The time now is 10:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration