user3207650 user3207650 - 1 year ago 60
Linux Question

Grep certain characters

So, in the following string:


I am trying to just extract the word MESSAGE. I have been playing around with grep trying to figure it out, but can now only get the first letter M to print.

grep -oP "body":"\K[^"]+,]

I tried using the above statement, but cant seem to get the whole word MESSAGE without quotes separated. This string MESSAGE changes, so the grep statement just has to be able to get the text in between "body":" and ".

Any help would be greatly appreciated!


This should work:

grep -oP '"body":"\K[^"]+' <<< '"body":"SOME MESSAGE"'