Skip to content

Instantly share code, notes, and snippets.

@mkropat
Created February 20, 2019 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkropat/b2ad34ee29cf0ecfc6c3862cfc103fd8 to your computer and use it in GitHub Desktop.
Save mkropat/b2ad34ee29cf0ecfc6c3862cfc103fd8 to your computer and use it in GitHub Desktop.
#!/bin/bash
sed -nE 's/^\s*(\S+)\s+\S+\s+(\S+)\s+\[([^]]*)\]\s+"(\S+)\s+(\S+)[^"]*"\s+(\S+)\s+(\S+)\s+"([^"]*)"\s+"([^"]*)".*/\1\n\2\n\3\n\4\n\5\n\6\n\7\n\8\n\9\x00/p' |
while IFS=$'\n' read -r -d $'\0' ip user timestamp method url status bytes referrer useragent; do
echo $method $url;
done
#while IFS= read -r line; do
# #mapfile -t parts < <(printf '%s\n' "$line" | IFS=$'\n' xargs -n1 printf '%s\n')
# mapfile -t parts < <(printf '%s\n' "$line" | sed -nE 's/^\s*(\S+)\s+\S+\s+(\S+)\s+\[([^]]*)\]\s+"(\S+)\s+(\S+)[^"]*"\s+(\S+)\s+(\S+)\s+"([^"]*)"\s+"([^"]*)".*/\1\n\2\n\3\n\4\n\5\n\6\n\7\n\8\n\9/p')
#
# ip="${parts[0]}"
# username="${parts[1]}"
# timestamp="${parts[2]}"
# method="${parts[3]}"
# url="${parts[4]}"
# status="${parts[5]}"
# bytes="${parts[6]}"
# referrer="${parts[7]}"
# useragent="${parts[8]}"
#
# #timestamp_time="$(printf '%s\n' "$timestamp" | sed -nE 's_^[^/]+/[^/]+/[^:]+:(.*)_\1_p')"
# #local_time="$(date --date="$timestamp_time" +%H:%M:%S)"
#
# printf '%s %s\n' "$local_time $method $url"
#done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment