- 论坛徽章:
- 0
|
本帖最后由 jils2013 于 2012-05-29 18:53 编辑
- [root@localhost shell]# cat list
- Li, W.; Bai, Y. C. D.; Yang, Z. H.; Feng, X.; Lu, X. H.; Laak, N. K.; Chan, K. Y.; Liu, C.
- [root@localhost shell]# awk 'BEGIN{RS=";|\n";FS=".";}
- {gsub(" ","",$0);
- lastname=substr($0,1,index($1,",")-1);gsub(lastname",","",$0);
- for(i=NF-1;i>0;i--)if(firstname==""){firstname=$i}else{firstname=firstname"."$i};
- if(str==""){str=firstname". "lastname}else{str=str" and "firstname". "lastname};
- firstname="";}
- END{print str}' list
- W. Li and D.C.Y. Bai and H.Z. Yang and X. Feng and H.X. Lu and K.N. Laak and Y.K. Chan and C. Liu
-
复制代码 蛋疼一个awk的,逻辑有点绕,应该有比较简单的 |
|