#!/bin/bash
# 脚本作用,封装grep指令,不输出冒号,减少复制打开的障碍,同时最后
# 只输出找到的文件的集合(不重复)
black='\033[0;30m'
red='\033[0;31m'
green='\033[0;32m'
brown='\033[0;33m'
blue='\033[0;34m'
purple='\033[0;35m'
cyan='\033[0;36m'
gray='\033[0;37m'
darkGray='\033[1;30m'
lightRed='\033[1;31m'
lightGreen='\033[1;32m'
yellow='\033[1;33m'
lightBlue='\033[1;34m'
lightPurple='\033[1;35m'
lightCyan='\033[1;36m'
white='\033[1;37m'
noColor='\033[0m'
numOfParameters=$#
parameters=$@
checkInput() {
if [ $1 -lt 1 ]; then
echo
echo -e ${brown}'No enough parameters'${noColor}
echo
exit
fi
}
listFileWhichContainStr() {
str=$1
restStr="${@:2}"
echo -e ${yellow}'Detail: '${noColor}
# -Il to ignore binary file
find -type f ! -iname tags -exec grep -Il "$str" $restStr --color=always {} + | awk -F: '{print $1, $2}' | uniq
echo
echo
echo -e ${yellow}'unique file list: '${noColor}
fileList=`find -type f ! -iname tags -exec grep -Il "$str" --color=always {} + | awk -F: '{print $1}' | uniq`
echo $fileList
echo
echo -e ${yellow}'line by line output:'${noColor}
for f in $fileList
do
echo -e ${purple}$f${noColor}
done;
}
# main:
checkInput $numOfParameters
listFileWhichContainStr $parameters