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!

AWK's printf strange behavior

Status
Not open for further replies.

sapfeer

IS-IT--Management
Aug 20, 2010
3
FI
Hi! Can someone explain the following:

Code:
/tmp # uname -sr
HP-UX B.11.31

/tmp # cat testf
1,1,1,1,NODE,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,NODE,1,2,1,1,1,1,1,1,1,1,1
1,1,1,1,NODE,1,3,1,1,1,1,1,1,1,1,1
1,1,1,1,NODE,1,4,1,1,1,1,1,1,1,1,1
1,1,1,1,NODE,1,5,1,1,1,1,1,1,1,1,1
1,1,1,1,NODE,1,6,1,1,1,1,1,1,1,1,1
1,1,1,1,NODE,1,7,1,1,1,1,1,1,1,1,1
1,1,1,1,NODE,1,8,1,1,1,1,1,1,1,1,1

/tmp # awk -F"," '{clients[$5]+=$7}
END { for (client in clients)
printf "%s\t-\t\t%d" client, clients[client] }' testf
awk: There are not enough parameters in printf statement %s     -               %dNODE.
 The input line number is 8. The file is testf.
 The source line number is 3.

/tmp # awk -F"," '{clients[$5]+=$7}
END { for (client in clients)
print client,"-", clients[client] }' testf
NODE - 36

I'm a bit confused...
 
Man... Sorry for such a ridiculous mistake...)) Thank you very much! It works now...
 
Hi

Nothing to apologize for. [tt]awk[/tt]'s error messages are not always accurate, so they can fool you abit on Monday morning.

One thing. Personally I prefer to format the [tt]printf[/tt] output by specifying field widths :
Code:
[b]printf[/b] [green][i]"%-8s-%17d"[/i][/green][teal],[/teal] client[teal],[/teal] clients[teal][[/teal]client[teal]][/teal]


Feherke.
 
Yeah, it's a good fashion. But mostly, you don't know the right width to specify...

Actually, I'm not an awk programmer, I'm just using it sometimes. So, such cases are more rare than usual...

Thanks a lot for explaination! It's great that there is a forum for such a small bit of all IT world like awk programming! I'm quite surprised
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top