0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

calc_license

Posted at
#!/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
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?