我试图让这个脚本工作以计算有多少 .doc 和 .pdf 类型的文件。但是我不断在 for 循环的最后一个括号上收到语法错误。
awk: ./parselog.awk:14: for ($7 in count)
awk: ./parselog.awk:14: ^ syntax error
这是 awk 脚本:
#!/usr/bin/awk -f
BEGIN {}
{
file = match($7, "/datasheets/")
doccheck = match(tolower($7), ".doc")
pdfcheck = match(tolower($7), ".pdf")
if( doccheck || pdfcheck )
{
count[$7]++
}
}
END{
for ($7 in count)
{
frequency = count[$7]
sub(/datasheets/,"",$7)
minusextension = $7
sub(/\....$/, "", minusextension)
print minusextension, $7, frequency
}
sort
}