| 关键词: tmp 文件 uniq sort nbsp 排序 内容 脚本 命令 以下 |
一家上海运维工程师的面试笔试题,关于脚本排序的。 题目: 文件 1、 2、 3 ,只能使用 sort 和uniq ,uniq -d ,uniq -u命令做以下排序。 X=1∩2∩3 Y=1-2-3 Z=1∪2∪3 解析: 先假设文件1内容为 a b c e,文件2的内容为b c d,文件3的内容为c d e. 预期结果是: X=1,Y=a,Z=a b c d e 解法如下,仅供参考和交流。当然不吝赐教,谢谢。 脚本: #!/bin/bash #author yueyangbeihan #只使用sort和uniq命令做以下排序 #x=1^2^3(取文件1 2 3的交集) sort /tmp/1 /tmp/2 | uniq -d > /tmp/x.1 sort /tmp/x.1 3 | uniq -d > /tmp/X #y=1-2-3(取文件1中不包含在文件2和3中的)方法一 sort /tmp/1 /tmp/2 /tmp/2 /tmp/3 /tmp/3 | uniq -u > /tmp/Y #y=1-2-3=1-(2+3)方法2 #取2 3文件并集 sort /tmp/2 /tmp/3 | uniq > /tmp/23 #y=1-23=1-(1^23) sort /tmp/1 /tmp/23 | uniq -d > /tmp/y.1 sort /tmp/1 /tmp/y.1 | uniq -u > /tmp/y.bak #此时y和y.bak是一摸一样的 #1U2U3取3个文件并集 sort 1 2 3 | uniq > /tmp/Z |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|