分类: LINUX
2011-05-23 17:41:45
if [ $# == 2 ];then u1=$1 u2=$2 elif [ $# == 3 ];then u1=$1 u2=$2 out=$3 else echo "Usage:$0 set1 set2 out_set" exit fi if [ $out"yes" != "yes" ];then cat $u1 $u2 | sort -u | sed "/^$/d" >$out else cat $u1 $u2 | sort -u | sed "/^$/d" 3,求集合的差 #!/bin/bash if [ $# == 4 ];then u1=$1 u2=$2 out=$3 same=$4 elif [ $# == 3 ];then u1=$1 u2=$2 out=$3 elif [ $# == 2 ];then u1=$1 u2=$2 else echo "Usage:$0 set1 set2 minus_set same_set " exit fi if [ -f $out ];then rm -rf $out fi if [ -f $same ];then rm -rf $same fi declare -a main_set=(`cat $u1 |sort -u`) declare -a minus_set=(`cat $u2 |sort -u`) main_length=${#main_set[@]} minus_length=${#minus_set[@]} i=0 j=0 while [ $i -lt $main_length -a $j -lt $minus_length ] do if [ ${main_set[$i]} \< ${minus_set[$j]} ];then if [ $out"yes" != "yes" ];then echo "${main_set[$i]}">>$out else echo "${main_set[$i]}" fi i=`expr $i + 1` continue; fi if [ ${main_set[$i]} \> ${minus_set[$j]} ];then j=`expr $j + 1` continue; fi if [ ${main_set[$i]} == ${minus_set[$j]} ];then if [ $same"yes" != "yes" ];then echo "${main_set[$i]}" >>$same else echo "${main_set[$i]}" fi i=`expr $i + 1` j=`expr $j + 1` continue; fi done while [ $i -lt $main_length ] do echo "${main_set[$i]}">>$out i=`expr $i + 1` done 这些脚本里面的前两个参数都是代表文件,这个文件里面是一些记录;第三四个参数视脚本功能变化; |