-1

I need help with pattern matching. I have the following text as the output of a command.

 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

I need to match the CopyLogs output to Completed. So basically after the execution of the command the output should be

COMPLETED        CopyLogs
COMPLETED        CopyLogs
COMPLETED        CopyLogs
COMPLETED        CopyLogs

How do I do that in a do while loop (for a retry logic). I tried the following

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"

but I just need to do this for "CopyLogs". How do I achieve that

user2890683
  • 403
  • 2
  • 6
  • 18
  • Curiously, the OP aleeady seems to have solved this, in a way. See http://stackoverflow.com/questions/23853440/syntax-error-in-shell-script-saying-unexpected-token – tripleee May 27 '14 at 13:43

1 Answers1

0
result=$(elastic-mapreduce --jobflow $JOBFLOW --list|grep -P '(COMPLETED[[:space:]]*CopyLogs)')

result will carry the required output.

-P perl-regular expression, please check man grep

PradyJord
  • 2,136
  • 12
  • 19