0

How do I remove a substring from a string using sed?

For example: I need to remove from all this:

/opt/openet/cdm/applications/SubscriptionManager/fwhome/config/log/corCTE_SM.pid process 18312 is not running

everything before CTE_SM and after too.

I need to extract CTE_SM from this line.

How do I do this?

Thank you so much.

Alessandro Melo

0

1 Answer 1

1

assuming that your string is always has capitals, I am replacing the lowercase letters & then splitting the string using awk.

you can try splitting the text even before replacing with sed.

myString='/opt/openet/cdm/applications/SubscriptionManager/fwhome/config/log/corCTE_SM.pid process 18312 is not running'   
echo $myString | sed 's/[a-z]//g' | awk -F/ '{print $(NF)}' | awk -F. '{print $1}'

result= CTE_SM

alternatively

echo $myString | awk -F/ '{print $(NF)}' | awk -F. '{print $1}'

result= corCTE_SM

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.