I have a text file which contains multiple sections and I want to print one of those sections.
Part of the file looks like
3. line 3
4. line 4
## Screenshots ##
1. line 1
2. line 2
3. line 3
4. line 4
## Changelog ##
3. line 3
4. line 4
From this I want to retrieve all lines between ## Screenshots ##
and the starting of the next section. Here the next section is ## Changelog ##
, but it could be anything. So the only thing which we can depend on is that it will start with ##
.
From another thread, I found the following code
sed -e "H;/${pattern}/h" -e '$g;$!d' $file
which I modified to
sed -e "H;/## Screenshots ##/h" -e '$g;$!d' readme.md
Now, it retrieves all lines starting from ## Screenshots ##
, but it prints all lines till the end of the file.
I then piped it to another sed
like
sed -e "H;/## Screenshots ##/h" -e '$g;$!d' readme.md | sed "/^##/q"
But now it prints only
## Screenshots ##
Is there anyway I can print all lines in the screenshots section?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…