# ワンライナー. 5. 合計の計算(特定の列の)

# Bash

cat a.txt | awk '{ sum += $3 } END { print sum }'

略さず書くならこう

cat a.txt | awk 'BEGIN { sum = 0 } { sum += $3 } END { print sum }'

# PHP

cat a.txt | php -B '$sum = 0;' -R '$sum += explode(" ", $argn)[2];' -E 'echo $sum . "\n";'

# PowerShell

Import-Csv a.csv | Measure-Object -Sum -Property Length

# Ruby

cat a.txt | ruby -ane 'BEGIN { sum = 0 }; sum += $F[2].to_i; END {puts sum}'

[ 📩 ご意見 ]