Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Filename in awk statement 2

Status
Not open for further replies.

wilmington

Technical User
Nov 21, 2002
3
US
I need help getting the filename out with my print statement. I want to prefix each matching line with the filename.

I am reading through a list of files in $logs and printing lines with error: and matching date.
$log |awk -vdd=`date +%d` '{ if ($3==dd && /error:/) print }' >>test.out

how can I prefix the filename with each matching line of output.

any help would be great.
thanks
 
The name of the log file prefixed to each matching line ?
Would this work ?

$log |awk -vlg=$log -vdd=`date +%d` '{ if ($3==dd && /error:/) print lg$0 }' >>test.out

Dickie Bird (:)-)))
 
awk -vdd=`date +%d` '{ if ($3==dd && /error:/) print FILENAME, $0 }' $logs/* >>test.out vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top