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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using printf to display information. 1

Status
Not open for further replies.

jalge2

Technical User
Feb 5, 2003
105
US
I'm grepping for a bunch of files, and appending that into a file.

ll |grep WCZI786A > /home/jma1/WCZI

The files obviously return
-rw-rw-rw- 1 lowes lowes 2250 Aug 11 02:07 WCZI786A.030811020716.Z
-rw-rw-rw- 1 lowes lowes 8020 Aug 11 02:19 WCZI786A.030811021917.Z
-rw-rw-rw- 1 lowes lowes 9823 Aug 11 03:00 WCZI786A.030811030014.Z

The problem is, I only want to display the filesize, date, time and file name with my script.
Here is my script

awk -F, 'BEGIN { print "DATE TIME SIZE FILE"
print "---- ---- ---- ----"}
{ printf "%-13s %-10s %-12s %-8s\n", $5, $6, $7, $8, }' /home/jma1/WCZI

And here is the error I am getting
syntax error The source line is 3.
The error context is
{ printf &quot;%-13s %-10s %-12s %-8s\n&quot;, $5, $6, $7, $8, >>> } <<<
awk: The statement cannot be correctly parsed.
The source line is 3.


So my question is, Is there a way to only take out the end information using printf, or do I have to display the entire thing.

Thanks for the help

Jason
 
I do it with a simple print:

awk 'BEGIN { print &quot;DATE TIME SIZE FILE&quot;
print &quot;---- ---- ---- ----&quot;}
{print $6&quot; &quot;$7&quot; &quot;$8&quot; &quot;$5&quot; &quot;$9}' /home/jma1/WCZI

Hope this helps

mad_murdock
 
In your script, it was the comma after the 8 that was the culprit $8, }'

Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top