免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1531 | 回复: 4
打印 上一主题 下一主题

文件替换 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-26 14:15 |只看该作者 |倒序浏览
两个文件,
file1:
user1  * passwd1  comment
user2  * passwd1  comment
user3  * passwd1  comment
user4  * passwd1  comment
...

file2:
user2 * passwd2  comment
user4 * passwd2  comment
...

处理后:
user1 * passwd1  comment
user2 * passwd2  comment
user3 * passwd1  comment
user4 * passwd2  comment
...

用file2中的行替换file1中的行.

请问应怎么操作? 谢谢!

[ 本帖最后由 rainren 于 2006-11-26 14:17 编辑 ]

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2006-11-26 14:41 |只看该作者
try:

  1. while read line;do grep ${line/ */} fileb || echo $line;done<filea
复制代码

论坛徽章:
0
3 [报告]
发表于 2006-11-26 15:10 |只看该作者
谢谢思路, 修改了一下可以用了.

论坛徽章:
0
4 [报告]
发表于 2006-11-28 13:36 |只看该作者
原帖由 寂寞烈火 于 2006-11-26 14:41 发表
try:

  1. while read line;do grep ${line/ */} fileb || echo $line;done<filea
复制代码



法王就是法王,真他妈的牛X。 鄙视你这么强悍

论坛徽章:
0
5 [报告]
发表于 2006-11-28 16:01 |只看该作者

回复 1楼 rainren 的帖子

来个比较烂的:
awk '{if(NR%2==0) print | "sed 's/1/2/g'" ; else print}' file1 | sort
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP