需求:
有两个文本:1.txt和2.txt,需要检查1.txt中的每一行是否在2.txt中出现,如果在2.txt中出现,需要打出是在哪一行。
简单地写了个脚本:
#!/bin/ksh
if [ $# -ne 2 ];
then
echo "Usage:$0 file1 file2";
exit 1;
fi
file1=$1
file2=$2
>result.txt
for i in `cat $file1`
do
echo `grep -n $i $file2` >> result.txt
done
sed '/^$/d' result.txt