求助 comm命令
-
- 帖子: 2
- 注册时间: 2012-03-27 9:55
求助 comm命令
本人用的是ubuntu8.04(不要鄙视版本低,这个版本在虚拟机中上网木问题的啊,高版本总有问题),知道comm命令是比较两个文件的,在终端试了一下,结果见图,我看书上介绍的是:comm结果会有三行,第一行显示第一个文件特有的行,第二行显示第二个文件特有的行,第三行显示两个文件共有的行。可是介绍的跟结果差得很大啊,到底怎么理解comm命令啊,已经困扰了半天了,急~
-
- 帖子: 1453
- 注册时间: 2008-05-24 8:30
Re: 求助 comm命令
代码: 全选
SYNOPSIS
comm [OPTION]... FILE1 FILE2
DESCRIPTION
Compare sorted files FILE1 and FILE2 line by line.
- Think1st
- 帖子: 45
- 注册时间: 2012-02-07 23:08
Re: 求助 comm命令
column:列wy200747055 写了:本人用的是ubuntu8.04(不要鄙视版本低,这个版本在虚拟机中上网木问题的啊,高版本总有问题),知道comm命令是比较两个文件的,在终端试了一下,结果见图,我看书上介绍的是:comm结果会有三行,第一行显示第一个文件特有的行,第二行显示第二个文件特有的行,第三行显示两个文件共有的行。可是介绍的跟结果差得很大啊,到底怎么理解comm命令啊,已经困扰了半天了,急~
在这里,问题比答案更抢手。
- Think1st
- 帖子: 45
- 注册时间: 2012-02-07 23:08
Re: 求助 comm命令
用脚本实现comm(果断想多了。。wy200747055 写了:本人用的是ubuntu8.04(不要鄙视版本低,这个版本在虚拟机中上网木问题的啊,高版本总有问题),知道comm命令是比较两个文件的,在终端试了一下,结果见图,我看书上介绍的是:comm结果会有三行,第一行显示第一个文件特有的行,第二行显示第二个文件特有的行,第三行显示两个文件共有的行。可是介绍的跟结果差得很大啊,到底怎么理解comm命令啊,已经困扰了半天了,急~

代码: 全选
#!/bin/bash
list1="\n"
list2="\n"
list3="\n"
exec 3< file1
exec 4< file2
while :
do
read line1 <&3
read line2 <&4
[[ "$line1" == "" && "$line2" == "" ]] && break
if [[ "$line1" == "" ]]
then
while [[ "$line2" != "" ]]
do
list2=$list2$line2"\n"
read line2 <&4
done
break
fi
while [[ "$line2" != "" && "$line2" != "$line1" ]]
do
list2=$list2$line2"\n"
read line2 <&4
done
if [[ "$line2" == "" ]]
then
while [[ "$line1" != "" ]]
do
list1=$list1$line1"\n"
read line1 <&3
done
break
else
list3=$list3$line1"\n"
continue
fi
done
printf "list1 belongs to file1: $list1"
printf "list2 belongs to file2: $list2"
printf "list3 belongs to file1 and file2: $list3"
exec 4<&-
exec 3<&-
list1 belongs to file1:
hello,ubuntu
hello,linux
hello,everyone
list2 belongs to file2:
hello,ubuntu
hello,kitt
hello,everyone
list3 belongs to file1 and file2:
hello,world
在这里,问题比答案更抢手。