Edit: I just realized that I read your question incorrectly, even after it was supported several times. My answer was off before! Now it should be more correct, but with some additional assumptions . Simple solutions can bring you so far!
This may help you with a few assumptions:
cat -s data | awk -vFS='\n' -vRS='\n\n' '/Deprecated from/ { getline; next } 1'
The cat
just squeezes out the extra lines, so awk
can work more easily. As for awk
, -vFS='\n'
tells him that the fields are separated by newlines, and -vRS='\n\n'
says that the records are separated by two newlines in a line. Then /Deprecated from/
finds entries that have this text, and { getline; next }
{ getline; next }
reads in the next record after it and makes it move on. 1
is a shortcut for printing lines that reach the next point.
The assumption is as follows :
- All comments and text blocks are separated by at least one blank line on both sides.
- Only comment blocks and text blocks alternate evenly
- There are no empty lines in text blocks.
So this may not be perfect for you. If these assumptions are in order, this makes awk
good choice for this job, as you can see: the script is tiny!
$ cat -s data | awk -vFS='\n' -vRS='\n\n' '/Deprecated from/ { getline; next } 1' -- /*********************************************************************************/ -- /* MIB table for Hardware */ -- /* Valid from: 543.44 */ -- /*********************************************************************************/ Some text some text Some text
In addition, as you can see, new lines that remain are pushed. To help you, you can change the command as follows:
$ cat -s data | awk -vFS='\n' -vRS='\n\n' '/Deprecated from/ { getline; next } { printf "%s\n\n", $0 }' -- /*********************************************************************************/ -- /* MIB table for Hardware */ -- /* Valid from: 543.44 */ -- /*********************************************************************************/ Some text some text Some text
source share