免费注册 查看新帖 |

Chinaunix

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

文件比较,多谢 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-07-08 15:20 |只看该作者 |倒序浏览
本帖最后由 gdutllf2006 于 2011-07-08 15:21 编辑

文件比较
ocs.unl:
3320577777|923125871352|
3320577777|923125871353|
3320577777|923125871354|
3344556679|923331234562|
3344556679|923331234533|

cares.unl
3320577777|923125871352|
3320577777|923331234564|
3344556679|923331234562|
3344556679|923331234560|

需要输出文件:
both.unl: 两边都存在的号码
3320577777|923125871352|
3344556679|923331234562|

in_ocs_notin_cares.unl: 在ocs.unl不在cares.unl中
3320577777|923125871353|
3320577777|923125871354|
3344556679|923331234533|

notin_ocs_in_cares.unl:不在ocs.unl在cares.unl中
3320577777|923331234564|
3344556679|923331234560|

命令如下:大家看有没有问题,现在没有环境测试, 如不行,看如何来实现??
sort -t"|" -k1,1n -k2n ocs.unl > ocs.unl.1
sort -t"|" -k1,1n -k2n cares.unl > cares.unl.1

comm -12 ocs.unl.1  cares.unl.1 > both.unl
comm -23 ocs.unl.1  cares.unl.1 > in_ocs_notin_cares.unl
comm -13 ocs.unl.1  cares.unl.1 > notin_ocs_in_cares.unl

论坛徽章:
0
2 [报告]
发表于 2011-07-08 15:27 |只看该作者
论坛里这种帖子太多了,搜一下吧

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
3 [报告]
发表于 2011-07-08 15:45 |只看该作者
回复 1# gdutllf2006
  1. awk -F'|' 'NR==FNR{a[$1]=1;b[$2]=$0;next}a[$1]&&b[$2]{print >"both";delete b[$2]}a[$1]&&!($2 in b){print >"notin_ocs_in_cares";}END{for(i in b) if(b[i])print b[i] >"in_ocs_notin_cares"}' ocs cares
复制代码

论坛徽章:
0
4 [报告]
发表于 2011-07-08 18:45 |只看该作者
回复 1# gdutllf2006


#!/bin/sh
awk '{a[$0]=$0" "FILENAME" "a[$0]}END{for(i in a){print a}}' ocs.unl cares.unl | awk '{if(NF==4){print $1>"both.unl"}else if($2=="ocs.unl"){print $1>"in_ocs_notin_cares.unl"}else{print $1>"notin_ocs_in_cares.unl"}}'

论坛徽章:
0
5 [报告]
发表于 2011-07-08 19:05 |只看该作者
回复  gdutllf2006


#!/bin/sh
awk '{a[$0]=$0" "FILENAME" "a[$0]}END{for(i in a){print a}}' ocs ...
ltomuno 发表于 2011-07-08 18:45



    这个思路不错,晚上测试下!
多谢各位
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP