I have a log file that looks like this:
11:34:17 PM CPU %user %nice %system %iowait %steal %idle
11:39:17 PM all 0.09 0.00 0.07 0.09 0.00 99.75
11:44:17 PM all 0.04 0.00 0.03 0.00 0.00 99.92
11:49:17 PM all 1.49 0.00 0.49 0.06 0.00 97.96
11:54:17 PM all 23.27 0.00 0.51 0.05 0.03 76.14
Average ....
I need to insert the date, time, %user, %system, %idle into the table
row_id (int) | date (date) | time (time) | hostname (varchar) | user (decimal) | system (decimal) | idle (decimal)
I need the time converted to hh:mm:ii (24 hr) as well. The date column needs to derive from the log file called YYYY-MM-DD_hostname_cpu.log
How can I do this in a shell script? I need help converting the time and grabbing the hostname which can be any length from 1 and 20.
#: awk 'BEGIN { OFS = "," } FNR == 1 { d = substr(FILENAME, 1, 10) } $2 ~ /^[AP]M$/ && $3 != "CPU" { print d, $1 " " $2, $4+$5, $6, $7+$8+$9 }' *_cpu.log >> new_file.log