作者:bjgirl来自:
代码:
cat dfile
#!/bin/ksh
#scriptname:dfile
function Usage {
echo "Usage: dfile [-x|-y|-z] file1 file2"
}
(($# != 3 )) && { Usage; exit 1; }
for i in $(cat $2);do
for j in $(cat $3);do
echo $i $j
done
done>a$$
same=$(awk '$1==$2 {print $1}' a$$)
X=$(echo 两个相同的行是:
echo $same|tr ' ' '\n')
diff1=$(awk '$1 != $2 {print $1}' a$$|uniq -d )
Y=$(echo "文件$2中存在而文件$3中不存在的行是:"
echo $same $diff1|tr ' ' '\n'|sort|uniq -u
echo "\n")
for n in $(cat $3);do
for m in $(cat $2);do
echo $n $m
done
done>b$$
diff2=$(awk '$1 != $2 {print $1}' b$$|uniq -d )
Z=$(echo "在文件$3中存在而文件$2中不存在的行是:"
echo -n $diff2 $same|tr ' ' '\n'|sort|uniq -u
echo "\n")
while getopts :xyz: arg
do
case $arg in
x) echo $X|tr ' ' '\n';;
y) echo $Y|tr ' ' '\n';;
z) echo $Z|tr ' ' '\n';;
\?) echo "选项错误!!!";Usage;;
esac
done
rm a$$ b$$
阅读(2122) | 评论(0) | 转发(0) |