I'm using bash shell. I have a YAML file from which I want to remove certain blocks of text.
/image-content:
post:
operationId: createEventPublic
summary: Process events
description: Process events
parameters: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Content'
responses:
'201':
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/Content'
/text-content:
post:
operationId: createStaticText
summary: Process text events
description: Process text events
parameters: []
requestBody:
...
I would like to remove (as an example) the block of text where the path contains "image-content". Normally I can use this to remove a single line with that text
sed -i '/image-content/d' ./infile
but I'm less clear how to replace every line after that up until the next line that begins with two spaces and a "/" (e.g. " /"). In the above, I would want to remove everything up until
/text-content:
Edit: Although this may not be valid openapi 3 swagger, I believe it is still a valid YAML file
openapi: 3.0.0
components:
/static/image-content:
post:
type: hello
/api/hello:
post:
type: hello
/static/css-content:
post:
type: hello
Ultimately, I would like to remove the blocks beginning with "/static". So the ending doc would be
openapi: 3.0.0
components:
/api/hello:
post:
type: hello
sed
program solves the task described in the question - inline comments are somewhat difficult to read. – AdminBee Dec 20 '23 at 15:14