LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 12:02 PM   #1
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
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 12:03 PM.
 
Old 12-02-2008, 12:09 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 12:20 PM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Original Poster
Rep: Reputation: 98
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 9 06-30-2016 05:30 PM
How to parameterize which field awk should print? dbland07666 Linux - Newbie 2 10-29-2007 03:49 PM
Using awk to print CLI-version of kaddressbook ? Yalla-One Programming 6 11-05-2006 02:51 PM
awk print lines that doesn't have a pattern huynguye Programming 5 05-04-2006 11:08 AM
Parse a filename with awk and sed chrisk5527 Programming 2 06-08-2004 06:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:12 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration