0

I'm writing a shell script which edits a docker-compose.yml file (running on MacOS).

I'm trying to delete a block which looks like so and is located at the end of the file:

  microservice-itai-ms:
    image: ms-itai-ms:master
    environment:
      NODE_ENV: 'development'
      NPM_TOKEN: 'SECRET'
    ports:
      - "3022:3000"
    depends_on:
      - "redis-cluster"

I'm running the following command in order to remove this block:

sed -i.bak '/.*itai-ms.*/,+9d' docker-compose.yml

9 is the number of lines including the pattern's line.

When I run the above command, I get the following error:

echo docker-compose.yml | sed -e '/.*itai-ms.*/,+9d'
sed: 1: "/.*itai-ms.*/,+9d
": expected context address

What am I doing wrong?

Itai Ganot
  • 5,873
  • 18
  • 56
  • 99

1 Answers1

1

If "itai-ms" really doesn't appear before the block, and the block really is at the end of the file, you can do this:

sed -i.bak '/itai-ms/,$d' docker-compose.yml

EDIT:

Roughly translated, the command is "from /itai-ms/ to $ [that is, from the first line containing "itai-ms" to the last line of the file] execute d [that is, delete the line]"

And if you want to pass "itai-ms" as a variable (call it X), try this:

"/$X/,\$d"

Note the double quotes and the escaped $.

Beta
  • 96,650
  • 16
  • 149
  • 150