简体   繁体   中英

with regex, why am i unable to get multiple lines to match in linux

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)*],' 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.*' 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)'

grep operates line by line.

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

docker inspect dev | tr -d '\n' | grep 'CreateCommand.*]'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM