我编写了一个bash脚本,它使用sed创建一个按关键字过滤文本的命令,然后为输出着色。我做了很多试验和错误,并搜索技术。我知道这可以改进。有人可以提供建议吗?
我希望能够像尾巴一样使用它 - 实时过滤和颜色尾部输出。有什么想法吗?
提前致谢!
function multigrep(){
#THIS WORKS - Recreate this, using input parameters
#sed -En '/(App)|(Spe)/p' ./flashlog.txt;
filename="/Users/stevewarren/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt";
paramString="";
for element in "$@"
do
#echo $element;
paramString="$paramString($element)|";
done
#TRIM FINAL | OFF PARAMSTRING
paramString=${paramString:0:${#paramString}-1};
#CREATE SED EXPRESSION - '/($1)|($2)|(...)/p'
paramString="'/$paramString/p'";
#CREATE SED FUNCTION, CALL ON FILE
paramString="sed -En $paramString ./flashlog.txt"
echo $paramString;
echo "${txtbld}$(tput setaf 7)" > ./flashlog_output.txt;
eval $paramString >> ./flashlog_output.txt;
echo >> ./flashlog_output.txt;
#cat ./flashlog_output.txt;
cat ./flashlog_output.txt | while read LINE
do
[[ $1 && ${1-x} ]] &&
if grep -q $1 <<<$LINE; then
echo "$(tput setaf 3)$LINE"
fi
[[ $2 && ${2-x} ]] &&
if grep -q $2 <<<$LINE; then
echo "$(tput setaf 7)$LINE"
fi
[[ $3 && ${3-x} ]] &&
if grep -q $3 <<<$LINE; then
echo "$(tput setaf 6)$LINE"
fi
done
}