【改變 AWK 切割欄位的方式 & 使用者定義函數】
$ vim reformat3.awk
BEGIN {
{ “date” | getline
print “Today is: “, $2, $3 > “today_rpt3”
print “====================” > “today_rpt3”
print “ID Number Arrival Time” > “today_rpt3”
close(“today_rpt3″)
}
{ FS=”[ t:]+”
sys_call = “sort -n >> today_rpt3”
}
}
{ arrival = HM_to_M($2, $3)
total += arrival
printf(“%6s %2s:%2s %sn”, $1, $2, $3, arrival > 480 ? “–” : “”) | sys_call
}
END {
close(“today_rpt3”)
close(sys_call)
printf(“Average arrival time = %d:%dn”, total/NR/60, (total/NR)%60) >> “today_rpt3”
}
function HM_to_M(hour, min) {
return hour * 60 + min
}
-> vim 命令模輸入 “:wq” (存檔離開)