ang@deepIn:~/Desktop/bash$ cat deep.sh
#!/bin/bash
file=$1
num=1;
#echo 'file:'$file
while true
do
echo 'num:'$num;
n1=`sed -n $num'p' ${file}`;
if [ -z "$n1" ];then
break;
fi
# 依赖者
w1=`echo $n1 | awk -F" " '{print $1}'`
# 被依赖者
#w2=`echo $n1 | awk -F" " '{print $2}'`
#echo $w1;
#echo $w2;
# 统计当前依赖着是否也直接被依赖
ret=`sed -n "/ $w1/p" $file | wc -l`
#echo 'ret1:'$ret
# 如果被依赖
if [ 0 -ne $ret ];then
#echo 'ret:'$ret
((num=num+1)); # 检测下一行
# 如果没有被依赖
else
# 如果没有被依赖就去除当前的节点
num=1;
`sed -i "/$w1 /d" $file`
#echo "sed -i '/$w1 /d' $file"
#break;
fi
done;
ang@deepIn:~/Desktop/bash$ cat a.txt
4 7
3 1
9 7
5 6
3 5
1 5
4 5
4 2
1 2
3 2
ang@deepIn:~/Desktop/bash$ ./deep.sh a.txt