bash - Parse a name out of a string -


there many server logs need analyzed. every log message string , i'm looping though stings.

problem:

i need see if string matches pattern

some text job *some_one_word_name* has finished, status some more text

i need save word between words job , has finished. in particular case (see below) save egimmswellhdr

 seq_loading_sor_to_landing..jobcontrol (dswaitforjob): job egimmswellhdr has finished, status = 1 (finished ok) 

you can use awk:

s='job egimmswellhdr has finished' awk -f 'job | has finished' '{print $2}' <<< "$s" egimmswellhdr 

and using pure bash:

[[ "$s" =~ "job "([^[:blank:]]+)" has finished" ]] && echo ${bash_rematch[1]} egimmswellhdr 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -