1

For a string like this,

"By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service."

I want to cut the string from last occurrence of 'our' to get the result: " Terms of Service."

1 Answer 1

2

Using bash you can do this:

s="By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service."
echo "${s##*our }"

Terms of Service.

If you cannot use bash for some reason then this awk should work:

awk -F 'our ' '{print $NF}' <<< "$s"

Terms of Service.
1
  • 1
    The ${parameter##word} notation is part of POSIX, not just a bashism.
    – ghoti
    Sep 26, 2018 at 19:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.