我需要有关模式匹配的帮助。我有以下文本作为命令的输出。
j-13PUDS1BDAAKK RUNNING ec2-54-242-150-167.compute-1.amazonaws.com Log Processing Job Flow
COMPLETED Setup Hive
RUNNING CopyLogs
PENDING CopyLogs
PENDING CopyLogs
PENDING CopyLogs
我需要将CopyLogs输出与Completed匹配。所以基本上在执行命令之后输出应该是
COMPLETED CopyLogs
COMPLETED CopyLogs
COMPLETED CopyLogs
COMPLETED CopyLogs
如何在do while循环中执行此操作(对于重试逻辑)。我尝试了以下
while :; do
result=$(elastic-mapreduce --jobflow $JOBFLOW --list) //lets say this returns the above output
[[ $result == +(*RUNNING*|*PENDING*|*WAITING*) ]] || break
done
echo "result now has no RUNNING or PENDING or WAITING"
但我只需要为" CopyLogs"执行此操作。我如何实现
答案 0 :(得分:0)
result=$(elastic-mapreduce --jobflow $JOBFLOW --list|grep -P '(COMPLETED[[:space:]]*CopyLogs)')
result
将带有所需的输出。
-P perl-regular expression,请检查man grep