sumcol
This commit is contained in:
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/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"
|
||||
Reference in New Issue
Block a user