- 论坛徽章:
- 2
|
本帖最后由 irockey 于 2017-06-18 00:57 编辑
标题没有说清楚现在有两个文件
- [root@154 home]# cat file1
- 3-1-1 POTV=1,POTA=0,POTP=2
- 1-4-76 POTV=1,POTA=0,POTP=1
- 7-1-19 POTV=1,POTA=1,POTP=1
- 3-2-33 POTV=1,POTA=1,POTP=2
- 4-1-10 POTV=1,POTA=1,POTP=2
- 7-1-2 POTV=1,POTA=1,POTP=2
- 3-1-10 POTV=1,POTA=1,POTP=2
- 3-2-34 POTV=1,POTA=1,POTP=2
- 7-2-22 POTV=1,POTA=1,POTP=1
- 5-1-19 POTV=1,POTA=1,POTP=1
- 1-4-77 POTV=1,POTA=1,POTP=1
- 7-1-3 POTV=1,POTA=1,POTP=2
- 3-2-35 POTV=1,POTA=1,POTP=1
- 7-1-4 POTV=1,POTA=1,POTP=1
- 5-1-2 POTV=1,POTA=1,POTP=2
- 7-2-23 POTV=1,POTA=1,POTP=1
- 3-2-36 POTV=1,POTA=1,POTP=1
- 3-1-11 POTV=1,POTA=1,POTP=2
- 1-4-78 POTV=1,POTA=1,POTP=2
- 3-2-37 POTV=1,POTA=1,POTP=2
- 7-1-6 POTV=1,POTA=1,POTP=1
复制代码- [root@154 home]# cat file2
- 1-1-1
- 1-1-2
- 1-1-3
- 1-1-4
- 1-1-5
- 1-1-6
- 1-1-7
- 1-1-8
- 1-1-9
- 1-1-10
- 1-1-11
- 1-1-12
- 1-1-13
- 1-1-14
- 1-1-15
- 1-1-16
复制代码 其中file1只有270行,
file2有345行,
file1的第一列内容都包含在file2中
这是两个文件的关系
要求:
我想以file2为样本,将file1第一列匹配file2行进行替换
即file2的第一行为
1-1-1
在file1中存在
1-1-1 POTV=1,POTA=2,POTP=0
然后将file2中内容替换为file1中该行内容(或者添加file1中第二列内容)
即变成以下样子
1-1-1 POTV=1,POTA=2,POTP=0
1-1-2
1-1-3
1-1-4
1-1-5
遇到问题:
想知道怎么能实现以file2为样本,进行替换
我的第一反应是awk,因为awk对段分离顺手,但后来发现思路不对
请大神指导
|
|