Skip to content

Instantly share code, notes, and snippets.

@kuninet
Last active December 14, 2015 03:29
Show Gist options
  • Save kuninet/6912c4974d789b47c95d to your computer and use it in GitHub Desktop.
Save kuninet/6912c4974d789b47c95d to your computer and use it in GitHub Desktop.
CSVから"TANAKA"さんのデータが出てくる回数をカウント
#
# CSVファイルから TANAKAのものが出現する回数をカウント
# 「本」が出てくる回数をカウント
#
BEGIN{
FS = ","
kaisu = 0 # 初期化は必須ではない
total = 0
hon = 0
}
$2 ~ /TANAKA/{ # 条件は正規表現で書けます
kaisu++
total += $4
}
($3 == "本"){ hon++ } # 中括弧は改行しなくてもOK
END{
print "TANAKAは" kaisu "回 出現しました"
print "合計は" total "です"
print "-------------------------------"
print "「本」は全体で" hon "回 出現しました"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment