- 论坛徽章:
- 25
|
本帖最后由 wh7211 于 2018-03-24 14:36 编辑
回复 10# zbs168
<<< awk4.0+
- 方法1:无中间文件,直接满足所有需求
- awk '$0!~/^$/{a[$14]=$1;b[$14]=$2;c[$14]=$3;d[$14]=$9;e[$14]=$18;f[$14]=$19}END{for(x in c){g=systime();h=strftime("%Y",g);split(c[x],i,":");a[x]=a[x]=="Jan"?1:a[x]=="Feb"?2:a[x]=="Mar"?3:a[x]=="Apr"?4:a[x]=="May"?5:a[x]=="Jun"?6:a[x]=="Jul"?7:a[x]=="Aug"?8:a[x]=="Sep"?9:a[x]=="Oct"?10:a[x]=="Nov"?11:a[x]=="Dec"?12:"";j=mktime(""h" "a[x]" "b[x]" "i[1]" "i[2]" "i[3]"");e[x]=e[x]=="valid"?j+f[x]:e[x];if(e[x]>=g||e[x]=="bad"){k[x]="("j") "d[x]" "x" "e[x]}};PROCINFO["sorted_in"]="@val_num_asc";for(y in k){print k[y]>"a.txt"}}' 1
- 方法2:生成中间文件并二次过滤
- 生成中间文件“a.txt”:
- awk '$0!~/^$/{a[$14]=$1;b[$14]=$2;c[$14]=$3;d[$14]=$9;e[$14]=$18;f[$14]=$19}END{for(x in c){split(c[x],g,":");h=strftime("%Y",systime());a[x]=a[x]=="Jan"?1:a[x]=="Feb"?2:a[x]=="Mar"?3:a[x]=="Apr"?4:a[x]=="May"?5:a[x]=="Jun"?6:a[x]=="Jul"?7:a[x]=="Aug"?8:a[x]=="Sep"?9:a[x]=="Oct"?10:a[x]=="Nov"?11:a[x]=="Dec"?12:"";i=mktime(""h" "a[x]" "b[x]" "g[1]" "g[2]" "g[3]"");e[x]=e[x]=="valid"?i+f[x]:e[x];j[x]="("i") "d[x]" "x" "e[x]};PROCINFO["sorted_in"]="@val_num_asc";for(y in j){print j[y]>"a.txt"}}' 1
- 对中间文件“a.txt”进行二次过滤并生成最终文件“b.txt”:
- awk '{a=systime()}$4!="bad"&&$4>=a||$4=="bad"{print>"b.txt"}' a.txt
复制代码
|
|