1

i would like to get everything that is inside the CreateCommand below:

so, i've tried CreateCommand(.|\n)*], on the regex101 site:

            "CreateCommand": [
                "docker",
                "run",
                "-p",
                "3000:3000",
                "-v",
                "/home/blah:/usr/src/app",
                "-w",
                "/usr/src/app",
                "--name",
                "dev",
                "node:18-bullseye-slim",
                "npm",
                "run",
                "dev"
            ],
"Umask": "0022"

and it works great.

Then, i try docker inspect dev | grep 'CreateCommand(.|\n)*],' and i get nothing.

I also tried:

docker inspect dev > insp.txt
cat insp.txt | grep 'CreateCommand(.|\n)*],'

so, it seems like i'm missing some kind of nuance here... because this gives me at least something:

cat insp.txt | grep 'CreateCommand.*' --> "CreateCommand": [

edit:

i have tried a few different variations, including taking off some from the right side:

cat insp.txt | grep -E 'CreateCommand((.|\n)*).*(?="Umask)'

2
  • 1
    If this is JSON, I suggest to use jq for this. Commented Aug 28, 2022 at 20:34
  • @Cyrus will have to check that out, now i know not to use grep on json Commented Aug 28, 2022 at 21:54

1 Answer 1

1

grep operates line by line; no regex will work.

Convert the output to a single line using tr to delete newlines, then use grep:

docker inspect dev | tr -d '\n' | grep 'CreateCommand.*]'
Sign up to request clarification or add additional context in comments.

1 Comment

ok i did not realize it is line by line. here are some ways i was able to do it: cat insp.txt | tr -d '\n\r\t ' | grep -oP '(CreateCommand").*(?="Umask)' or podman inspect dev | python -c 'import json, sys; print(" ".join(json.loads(sys.stdin.read())[0]["Config"]["CreateCommand"]).encode("utf-8") );'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.