Issue
I want to be able to select all text between two strings that are found on two lines. A few complicating specifics:
- One of these strings is simple text (e.g., "match me")
- One of these strings is the docstring symbol (""")
- These two strings will not be found at the start of the line (if you count whitespace)
E.g.,
match me: XXXXX
I want this
I want this
I want this
"""
I would ideally like to
- get the text between the two strings,
- remove the whitespace and
- remove the strings themselves
E.g., ideal output:
I want this
I want this
I want this
Any guidance on how to do this would be greatly appreciated.
I have tried a variety of solutions using awk and sed but have been unable to match only the text meeting all of the above conditions.
Solution
Using any POSIX awk:
$ awk '{sub(/^[[:space:]]+/,"")} f{if (/^"""/) f=0; else print} /^match me/{f=1}' file
I want this
I want this
I want this
I'm guessing at some of your requirements, see my comment. If there's only 1 such block in your input you could change f=0
to exit
for improved efficiency.
Answered By - Ed Morton Answer Checked By - Robin (WPSolving Admin)