I am using this sed command to extract a json value for a key, say MyKey..


For a json string like,

{"myKey" : 1, "yourKey": 2}

It returns what i need,


But what does \1 action in the above sed command mean?


\([^"]*\) defines a group of characters, the group is actually the found contents between the two braces (), the braces need to be escaped hence \( and \)

\1 is the contents of the first group

There could be several groups defined using multiple sets of brace pairs, they are numbered incrementally and each one can be referenced as \n (e.g. \1, \2, \3 etc) hence the name: backreference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy