Sample Header Ad - 728x90

How do I remove all specific sub-sections of a specific header in a YAML file?

6 votes
5 answers
11091 views
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
Asked by Dave (2808 rep)
May 7, 2021, 08:28 PM
Last activity: May 3, 2025, 07:22 PM