您的位置:首页 > 博客中心 > 网络系统 >

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

时间:2022-04-03 11:41

##!/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

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

本类排行

今日推荐

热门手游