Skip to content

Instantly share code, notes, and snippets.

@NitriKx
Created September 1, 2014 17:18
Show Gist options
  • Save NitriKx/273b5fa97ef3efd8d757 to your computer and use it in GitHub Desktop.
Save NitriKx/273b5fa97ef3efd8d757 to your computer and use it in GitHub Desktop.
[BASH 4.0] - Compute AWS S3 Data Transfert Out parsing S3 Logging files
# The key of the map is the first folder name
PATTERN=".*/mybucket/([^/]+)/.*200 - ([0-9]+) .*"
unset costMap
# Requires Bash 4.0
declare -A costMap
for file in $(ls .); do
echo "Processing ${file}...."
while read fileLine; do
if [[ "$fileLine" =~ ${PATTERN} ]]; then
echo "costMap[${BASH_REMATCH[1]}]=$(( ${costMap[${BASH_REMATCH[1]}]} + ${BASH_REMATCH[2]})); ";
costMap[${BASH_REMATCH[1]}]=$(( ${costMap[${BASH_REMATCH[1]}]} + ${BASH_REMATCH[2]} ));
fi
done < ${file};
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment