Created
September 1, 2014 17:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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