Skip to content

Instantly share code, notes, and snippets.

@jamesattard
Created March 14, 2016 18:03
Show Gist options
  • Select an option

  • Save jamesattard/aba01ccbc7e50d6551a1 to your computer and use it in GitHub Desktop.

Select an option

Save jamesattard/aba01ccbc7e50d6551a1 to your computer and use it in GitHub Desktop.
summarise r2d counts
#!/bin/bash
sum=0
[ $# -ge 1 -a -f "$1" ] && input="$1"
cat $input | grep -o '[0-9]*' | while IFS= read -r line
do
sum=$((sum + line))
echo $sum >> /tmp/sum.tmp
done
tail -1 /tmp/sum.tmp
rm /tmp/sum.tmp
@jamesattard
Copy link
Author

~/code  cat garbage.txt
output from DS1988:

1258

output from DS1989:

1326

output from DS1990:

1184

output from DS1991:

1265

output from DS1992:

1479

output from DS1993:

1345

~/code  cat garbage.txt | ./summarise2.sh
7857

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment