Linuxコマンドgrepフィルタ比較2つのファイルの違い
2024 ワード
#!/bin/bash
#different in file1 and file2
#author:vaedit
#date:2017/8/20
#read -p " " file1
#read -p " " file2
function print_help(){
echo " "
echo "useage -f file1 file2"
}
function grepfile(){
if [ -f $file1 -a -f $file2 ]
then
FILE1_LENTH=`wc -l $file1 | awk '{print $1}'`
FILE2_LENTH=`wc -l $file2 | awk '{print $1}'`
if [ "$FILE1_LENTH" -gt "$FILE2_LENTH" ]
then
echo "$file1 ,$file2 "
echo -e "\e[32;40;1m===========================================\e[0m"
echo "==========================================="
grep -vwf "$file2" "$file1"
echo "==========================================="
echo -e "\e[32;40;1m===========================================\e[0m"
else
echo "$file2 ,$file1 "
echo -e "\e[32;40;1m===========================================\e[0m"
echo "==========================================="
grep -vwf "$file1" "$file2"
echo "==========================================="
echo -e "\e[32;40;1m===========================================\e[0m"
fi
else
echo " "
exit 1
fi
}
while test -n "$1";do
case "$1" in
-h| --help)
print_help
exit
;;
-f| --file)
file1="$2"
file2="$3"
grepfile
shift 3
;;
*)
echo "==========================================="
print_help
exit
esac
done