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

Help Printing decimal with mixed fields

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
I have a line that looks like this:

Jane likes math 13

My awk program:
Code:
awk '{print $1, $2, $3/14}'
Results:
Code:
Jane likes 0
Desired:
Code:
Jane likes 0.21

I was playing with the printf command but I can't get it to print both numbers and words out.

Code:
# echo "40052.96 hello" |awk '{printf "%2.2f\n",$0}'
40052.96

 
I think I figured it out.
Code:
.... | awk 'BEGIN { OFMT = "%2.2f" }; {print $2, $12, $13, $14/86400+25569-6/24, $15, $16/86400+25569-6/24, $19, $20}'

If anybody has a better way, let me know.

Thanks
 
13 is $4 not $3
also 13/4 =0.928
Code:
echo Jane likes math 13|awk '{printf("%4s%6s%2s%1.2f\n", $1, $2," ", $4/14)}'
Jane likes  0.93
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top