- 论坛徽章:
- 0
|
yinyuemi 发表于 2012-10-05 22:57 ![]()
回复 3# tyguaike
不好意思呀,好像我不会用呀。你看看我用得对不对呀!- dong@dong-System-Product-Name:~/cp$ cat 147.awk
- # 147,258,369,归类法
- # awk -f 147.awk file
- BEGIN{t["147"]="C";t["258"]="A";t["369"]="B";
- for(i=1;i<=split("147|258|369",a,"|");i++){for(j=1;j<=split(a[i],b,"");j++){m[b[j]]=a[i]"|"t[a[i]]}}
- }
- {s=substr($0,1,1);md=substr($0,2,2);e=substr($0,4,1);
- x=NR-n[m[s]];
- if(s in m){temp=(m[e]?m[e]:e);temp=substr(temp,length(temp),1)
- print $0,(substr(m[s],length(m[s]),1) md temp),n[m[s]]?x:"" > substr(m[s],1,length(m[s])-2)".txt";
- n[m[s]]=NR;}
- }
- dong@dong-System-Product-Name:~/cp$ cat 147test
- 0000
- 2580
- 3678
- 6571
- 1987
- 3825
- 5391
- 8302
- 4367
- 2317
- 7789
- 9426
- dong@dong-System-Product-Name:~/cp$ awk -f 147.awk 147test
- dong@dong-System-Product-Name:~/cp$
复制代码 |
|