Search code examples
linuxawkgrepfindprintf

Print the result of string after a particular key word


Below output is an one liner output, where ma-name & emailID are common values. I would need to print the next values of ma-name & emailID parallel one after the other. please suggest a way to do it

sample text file

{"ma":{"ma-name":"svc"},"team-dl":{"emailID":"opt"},"disable":{"disable":false}},{"ma":{"ma-name":"ns"},"team-dl":{"emailID":"Solutions"},"disable":{"disable":false}},{"ma":{"ma-name":"mea"},"team-dl":{"emailID":"DISTA"},"disable":{"disable":false}}

Expected output

svc opt
ns Solutions
mea DISTA

Solution

  • Using sed to turn the input into valid JSON so we can run jq on it:

    $ sed 's/.*/[&]/' file |
        jq -r '.[] | (."ma"."ma-name" + " " + ."team-dl"."emailID")'
    svc opt
    ns Solutions
    mea DISTA