awk printf syntax
am 23.10.2007 19:29:40 von Gretch
The issue, e.g.:
wget -O-
"http://finance.yahoo.com/d/quotes.csv?s=GOOG,^HSI&f=sl1d1t1 c1ohgv&e=.csv"
2>/dev/null | awk -F"," '{print $1"\n"$2"\n"$5" "$5/($2-$5)*100"%\n"}'
"GOOG"
664.51
+13.76 2.11448%
"^HSI"
29376.859
+1003.229 3.53578%
How would I use the printf format of awk to leave the "+/-" field of the
third line at whatever number of decimal places it currently has, but limit
the "%" field to only 1 decimal place, preferably rounded rather than
truncated? I couldn't quite make sense of the man page, sorry.
Thank you.
Re: awk printf syntax
am 23.10.2007 19:51:18 von Stephane CHAZELAS
2007-10-23, 10:29(-07), Gretch:
> The issue, e.g.:
>
> wget -O-
> "http://finance.yahoo.com/d/quotes.csv?s=GOOG,^HSI&f=sl1d1t1 c1ohgv&e=.csv"
> 2>/dev/null | awk -F"," '{print $1"\n"$2"\n"$5" "$5/($2-$5)*100"%\n"}'
>
> "GOOG"
> 664.51
> +13.76 2.11448%
>
> "^HSI"
> 29376.859
> +1003.229 3.53578%
>
> How would I use the printf format of awk to leave the "+/-" field of the
> third line at whatever number of decimal places it currently has, but limit
> the "%" field to only 1 decimal place, preferably rounded rather than
> truncated? I couldn't quite make sense of the man page, sorry.
[...]
printf "%s\n%s\n%s $.1f%\n", $1, $2, $5, $5/($2-$5)*100
If I understand the question correctly.
--
Stéphane
Re: awk printf syntax
am 23.10.2007 20:24:42 von Glenn Jackman
At 2007-10-23 01:51PM, "Stephane CHAZELAS" wrote:
> printf "%s\n%s\n%s $.1f%\n", $1, $2, $5, $5/($2-$5)*100
typo warning ---------^
%.1f
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
Re: awk printf syntax
am 24.10.2007 05:32:59 von Gretch
In news:slrnfhsd93.gl6.stephane.chazelas@spam.is.invalid,
Stephane CHAZELAS wrote:
>> wget -O-
>>
"http://finance.yahoo.com/d/quotes.csv?s=GOOG,^HSI&f=sl1d1t1 c1ohgv&e=.csv"
>> 2>/dev/null | awk -F"," '{print $1"\n"$2"\n"$5"
>> "$5/($2-$5)*100"%\n"}'
>>
>> "GOOG"
>> 664.51
>> +13.76 2.11448%
>>
>> "^HSI"
>> 29376.859
>> +1003.229 3.53578%
>>
>> How would I use the printf format of awk to leave the "+/-" field of
>> the third line at whatever number of decimal places it currently
>> has, but limit the "%" field to only 1 decimal place, preferably
>> rounded rather than truncated? I couldn't quite make sense of the
>> man page, sorry.
> [...]
>
> printf "%s\n%s\n%s $.1f%\n", $1, $2, $5, $5/($2-$5)*100
> If I understand the question correctly.
Thank you _very_ much; with a little additional effort I find
printf "%s\n%s\n%s %+.1f%\n\n", $1, $2, $5, $5/($2-$5)*100
to work quite nicely, and with your generous assistance have learned a great
deal about the Subject:.