shell两文件对比,相同字符取出到另一个文本

##!/bin/bash
echo "pleases enter a.txt file(enter q to exit)"
read -dq A

echo " "

echo "pleases enter b.txt file(enter q to exit)"
read -dq B

echo " "

cat > /root/a.txt <<Eof
$A
Eof
cat > /root/b.txt <<Eof
$B
Eof
C=`cat /root/a.txt | grep -f /root/b.txt`
D=`cat /root/a.txt | grep -f /root/b.txt | egrep -v "^$" | wc -l`
if [ $D -eq 0 ];then
     echo "没有相同字符,请重新输入,标识:N"
fi
if [ $D -ge 1  ];then
echo "恭喜!有相同字符,标识:Y"
cat > /root/c.txt << Eof
$C
Eof
echo "the c.txt file is:"
echo $C
fi

本文出自 “流星宇” 博客,谢绝转载!

你可能感兴趣的:(shell两文件对比,相同字符取出到另一个文本)