【使用 getline 來讀取資料】
$ vim reformat4.awk
awk ‘
BEGIN {
result = “today_rpt4”
sys_sort = “sort -n >> ” result
“date” | getline
print “Today is: “, $2, $3 > result
print “====================” > result
print “ID Number Arrival Time” > result
close(result)
FS = “[ t:]”
late_file = $2 “_late.dat”
while (getline < late_file > 0) cnt[$1] = $2
close(late_file)
}
{
arrival = HM_to_M($2, $3)
total += arrival
if (arrival > 480) {
mark = “–”
cnt[$1]++
} else mark = “”
message = cnt[$1] ? cnt[$1] ” times” : “”
printf(“%8s %2d:%2d %5s %sn”, $1, $2, $3, mark, message) | sys_sort
}
END {
close(result)
close(sys_sort)
printf(“Average arrival time = %d:%dn”, total/NR/60, (total/NR)%60) >> result
for ( any in cnt )
print any, cnt[any] > late_file
}
function HM_to_M(hour, min) {
return hour * 60 + min
}
‘ $*
-> vim 命令模輸入 “:wq” (存檔離開)
(閱讀全文…)