I do have a variable containing one line like this:
Waiting for job XXXXXX to start
I needed to get the 'XXXXXX' literal, so I did the following:
job_interno=`echo $log_exec | sed 's/.*Waiting for job \([^ to start]*\).*/\1/' `
#other stuff
Now, my variable is have more than line like that:
Waiting for job XXXXXX to start
Waiting for job YYYYYY to start
Now, I need to loop over all these lines, get the job name (XXXXXX, YYYYYY...) and execute what is in #other stuff for every single line, but I dont know how
The furthest I got is to get how many times I do have to iterate:
$ cat script.sh
a='Waiting for job YYYYYY to start
Waiting for job XXXXXX to start'
while read line; do
echo "$line"
done <<<"$a"
$ bash script.sh
Waiting for job YYYYYY to start
Waiting for job XXXXXX to start
a='LINE HELLO
Waiting for job XXXXXXX to start
LINE HOW ARE YOU DOING
LINE FINE
Waiting for job YYYYYY to start
Waiting for job ZZZZZZ to start
MORE LINES'
echo "$a" | while read line; do
if echo "$line" | grep -q '^Waiting'; then
echo "do something with '$line'"
fi
done
Thanks very much for your replies, now I feel I am closer
I tried what you suggested, but it seems that I am losing lines when retrieving the information, let me explain:
My script is doing the following:
log_exec=`$path_ds_ex/dsjob -logdetail $proyecto $job`
#(doing this because need to use this many times later on)
numtimes=`echo $log_exec | grep "Waiting for job" | grep "to start" | wc -l `
echo $numtimes