#!/usr/bin/awk -f
BEGIN {
FS=" "
OFS=","
}
/type=Usage/ {
date = $1
idx = ""
bytes = 0
for (i = 1; i <= NF; i++) {
if ($i ~ /^idx=/) {
idx = gensub(/^idx="([^"]+)".*$/, "\\1", "1", $i)
}
if ($i ~ /^b=/) {
bytes = gensub(/^b=([0-9]+).*$/, "\\1", "1", $i)
}
}
if (idx != "" && bytes > 0) {
if (!(idx in indices)) {
indices[idx] = 1
}
usage[date, idx] += bytes
}
}
END {
# ヘッダー行の出力
header = "\"Date\""
PROCINFO["sorted_in"] = "@ind_str_asc"
for (idx in indices) {
header = header ",\"" idx "\""
}
print header
# データ行の出力
PROCINFO["sorted_in"] = "@ind_str_asc"
for (date in usage) {
split(date, parts, SUBSEP)
current_date = parts[1]
if (!(current_date in printed_dates)) {
printed_dates[current_date] = 1
output_line = "\"" current_date "\""
for (idx in indices) {
total_bytes = usage[current_date, idx]
if (total_bytes == "") {
total_bytes = 0
}
output_line = output_line "," "\"" total_bytes "\""
}
print output_line
}
}
}
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme