标签:date 内容 exit bash bin int 脚本 ase while
1. 该脚本用来比较两个文件中,其中一个文件比另一个文件多的行,常用来工作环境中,对比得出多余的ip地址
#!/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
标签:date 内容 exit bash bin int 脚本 ase while
原文地址:http://www.cnblogs.com/vaedit/p/7554084.html