samedi 8 mai 2021

Regex for pattern matching in shell script and extract the match part

Hope you are doing.

I need help in regex in the shell script.

the input is:

PM_path='SubNetwork=IMS,SubNetwork=IMS,MeContext=R9NEXRERNFVCSS01_PS'**PM_path='SubNetwork=IMS,SubNetwork=IMS,MeContext=R9NEXRERNFVCSS01_PS'

the output I want as:

R9NEXRERNFVCSS01_PS that is everything after the last equal sign.

Right now I have implemented it as below:

if [[ $PM_path =~ MeContext=([a-zA-Z0-9_]+) ]]; then  
      NODE_NAME=${BASH_REMATCH[1]}
 echo "the value is matched";

So here I have put a check at MeContext and this is a part of PM_path.

I wanted to make it more generic like select everything which appears after the last equal sign.

Please help.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire