Code for parsing a key/value in in file from shell script

bash, linux

Solution

if `HereIsAKey` is unique in your file, try this with grep:

myVar=$(grep -Po "(?<=^HereIsAKey ).*" file)

Problem

I have a file that I need to look up a value by key using a shell script. The file looks like: ``` HereIsAKey This is the value ``` How can I do something like: ``` MyVar=Get HereIsAKey ``` and then MyVar should equal "This is the value". The key has no whitespace and the value should be everything following whitespace after the key.

Original source

Related problems