アプリ版:「スタンプのみでお礼する」機能のリリースについて

awkスクリプトをつかって、以下の表を 

2501:Chester's Pit:21.56:food
2502:Harry's Hospital:235.00:medical
2503:Lucrezia's Pharmacy:30.00:medical
2504:Cat Care Specialists:115.00:pet
2505:No Frills Supermarket:85.63:food
2506:Taco Frenzy:8.99:food
2507:The Kitty Boutique:56.09:pet
2508:Kitty Litter Factory Outlet:45.66:pet
2509:Greasy Spoon Cafe:10.50:food

次の表のように書き換えたいのですが、どなたがご教授願えませんか?

food
2501:Chester's Pit:21.56
2505:No Frills Supermarket:85.63
2506:Taco Frenzy:8.99
2509:Greasy Spoon Cafe:10.50
medical
2502:Harry's Hospital:235.00
2503:Lucrezia's Pharmacy:30.00
pet
2504:Cat Care Specialists:115.00
2507:The Kitty Boutique:56.09
2508:Kitty Litter Factory Outlet:45.66

TOTALS
food:126.68
medical:265
pet:216.75



よろしくお願いいたします。

A 回答 (1件)

順番は、ちょっと変わってしまいますけど、こんな感じでいいかと


BEGIN { FS =":" }
{
data[$4,kind[$4]++]= $1 ":" $2 ":" $3
sum[$4] += $3
}
END {
for( x in kind){
printf("%s\n", x)
for( i=0 ; i < kind[x];i++){
printf("%s\n",data[x, i])
}
}
printf("\nTOTALS\n")
for( x in kind){
printf("%s:%g\n", x, sum[x])
}
}
    • good
    • 0
この回答へのお礼

BLUEPIXYさま

本当に助かりました。
感謝しています。

ありがとうございました。

お礼日時:2004/09/26 11:46

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!