Chinaunix首页 | 论坛 | 博客
  • 博客访问: 71669
  • 博文数量: 11
  • 博客积分: 286
  • 博客等级: 二等列兵
  • 技术积分: 136
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-03 15:31
文章分类

全部博文(11)

文章存档

2015年(5)

2014年(3)

2011年(3)

我的朋友

分类: LINUX

2015-07-01 11:10:05

文件1:
SEQUENTIAL
1001;[authentication username=1001 password=123456]
1002;[authentication username=1002 password=123456]
1003;[authentication username=1003 password=123456]
1004;[authentication username=1004 password=123456]
1005;[authentication username=1005 password=123456]
1006;[authentication username=1006 password=123456]
1007;[authentication username=1007 password=123456]
1008;[authentication username=1008 password=123456]
1009;[authentication username=1009 password=123456]

文件2:
1001;tag=dcb13e6a;Call-ID: MGRlNTQ4YzBkZmM1YjdiZTdjMGU4MzRlMmE3ODUwZGU@192.168.1.16

合并后文件3:
SEQUENTIAL;
1001;[authentication username=1001 password=123456];1001;tag=dcb13e6a;Call-ID: MGRlNTQ4YzBkZmM1YjdiZTdjMGU4MzRlMmE3ODUwZGU@192.168.1.16
1002;[authentication username=1002 password=123456];
1003;[authentication username=1003 password=123456];
1004;[authentication username=1004 password=123456];
1005;[authentication username=1005 password=123456];
1006;[authentication username=1006 password=123456];
1007;[authentication username=1007 password=123456];
1008;[authentication username=1008 password=123456];
1009;[authentication username=1009 password=123456];

合并命令:

  1. awk 'BEGIN{FS=";"}{if(NR==FNR){id[$1]=$0}else{print $0";"id[$1] > "file3"}}' file2 file1

NR:当前记录数
FNR:同NR,但相对于当前文件。
阅读(1302) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~