Skip to content
Advertisement

Extract a block from file between two lines

I have a file/output containing this :

JavaScript

I would like to extract all public subnet id and print them without, and white space.

I used this regex

JavaScript

And the output is :

JavaScript

But I would like to get this instead:

JavaScript

In fact I told sed to replace spaces and newlines with nothing (s/[[:space:]]//g) and then it also replace the first new line and then brings the first subnet up, so I would to process the regex after the first newline and when I try this

JavaScript

It gives no ouput, means it doesn’t match anything.

Please can help improve the above regex to give only subnets ids in seperated lines?

Advertisement

Answer

Another approach this sed:

JavaScript
  • '/public_subnets_ids/,/]/: from line containing public_subnets_ids up to next line containing ]
  • //!: in matching lines, except those matching the addresses
  • //!{s/[ ,]*//g;p;}: removes commas and space characters and output result
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement