- 论坛徽章:
- 0
|
一个awk处理文本问题
笨笨的写一个
- [kennyyu@haha dataDir]$ more a.txt
- 0 222 a
- 1 222 a
- 2 222 a
- 3 333 a
- 4 444 a
- 5 333 a
- 6 777 b
- 7 333 b
- 8 222 b
复制代码
- [kennyyu@haha dataDir]$ more deal.awk
- #! /bin/awk -f
- {i++;a[i]=$0} \
- END{ \
- for(j=1;j<=i;j++) \
- { \
- if(a[j]=="") continue; \
- split(a[j],aArry," "); \
- for(k=1;k<=i;k++) \
- { \
- split(a[k],bArry," "); \
- if(aArry[2]==bArry[2]&&aArry[3]!=bArry[3]) \
- {a[j]="";a[k]="";break}\
- } \
- }; \
- for (t=0;t<=i;t++) if(a[t]!="") print a[t]
- }
复制代码
运行:
- [kennyyu@haha dataDir]$ ./deal.awk a.txt
- 1 222 a
- 2 222 a
- 4 444 a
- 5 333 a
- 6 777 b
复制代码
OS: RH linux 9.0
GNU Awk 3.1.1 |
|