20 lines
227 B
Bash
20 lines
227 B
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
if [ "$#" -ne 2 ]; then
|
||
|
|
echo "Usage: $0 <file> <column_number>"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
file="$1"
|
||
|
|
col="$2"
|
||
|
|
|
||
|
|
awk -v c="$col" '
|
||
|
|
{
|
||
|
|
if ($c ~ /^-?[0-9]+([.][0-9]+)?$/)
|
||
|
|
sum += $c
|
||
|
|
}
|
||
|
|
END {
|
||
|
|
print sum
|
||
|
|
}
|
||
|
|
' "$file"
|