数据样本
subdate score url
2006-04-01 4299 http://aaa.163.com/111.html
2006-04-01 6999 http://aaa.163.com/121.html
2006-04-02 7899 http://aaa.163.com/131.html
2006-04-02 4999 http://aaa.163.com/141.html
2006-04-02 8999 http://aaa.163.com/151.html
2006-04-04 9999 http://aaa.163.com/161.html
2006-04-04 8999 http://aaa.163.com/171.html
2006-04-05 4999 http://aaa.163.com/181.html
提取
仅列出 2006-04-01 所有信息 。
{ if ($1 == “2006-04-01”) print $0 }
仅列出 URL信息。
{ print $3 }
仅列出 日期信息,要求不可重复。
{ dtList[$1]++ } END { for (dtStr in dtList) print dtStr}
统计
统计 每天 出现的URL数量 。
{ dtList[$1]++ } END { for (I in dtList) print dtList[i] “\t” I }
统计 每天 出现的score > 5999 的URL数量 。
加上 if ($2 > 5999)
计算 2006-04-01 所有 score 总和。
{ total+=$2 } END { print “total ” total }
计算 2006-04-01 score 平均值。
BEGIN{total=0;count=0}{ total += $2; count++; } END { print “avg:” total/count }
显示每个字段信息。
awk '{ for (i=1;i<=NF; i++) print “$” i ":\t" $i }‘
计算某列的和(该列为数字):
awk 'BEGIN{sum=0}{sum+=$2}END{print sum}'
在某行前加上某个字符串
awk '{printf "data/news/newsbuffer3-060904_dataDir/";printf $0;printf "\n";}' ./perf.list > l.txt
提取出最后一列
cat performance.list |awk '{print $NF}' >>perf.list