【发布时间】:2021-11-26 15:47:58
【问题描述】:
如何使用for 循环从文件中找到错误(Error1、Error2、Error 3)。
一个文件包含来自 4 不同机器的三种类型的错误 (strings)。任何机器都可能有任意数量的错误。 whiptail 用于在发现错误时创建pop-up window。
#!/bin/sh
if grep -R "Error1 in Machine 1" /home/new/Report.txt
then
echo "Error1 found in Machine 1"
whiptail --title "Report Error" --msgbox "Error 1 in Machine 1" 8 78
else
echo "No Error found"
fi
if grep -R "Error2 in Machine 1" /home/new/Report.txt
then
echo "Error2 found in Machine 1"
whiptail --title "Report Error" --msgbox "Error 2 in Machine 1" 8 78
else
echo "No Error found"
fi
if grep -R "Error2 in Machine 2" /home/new/Report.txt
then
echo "Error2 found in Machine 2"
whiptail --title "Report Error" --msgbox "Error 2 in Machine 2" 8 78
else
echo "No Error found"
fi
if grep -R "Error3 in Machine 3" /home/new/Report.txt
then
echo "Error3 found in Machine 3"
whiptail --title "Report Error" --msgbox "Error 3 in Machine 3" 8 78
else
echo "No Error found"
fi
【问题讨论】:
-
grep中的-R选项的用途是什么?