0

Say for example I have a file with contents like this:

# TODO: Optimize this.
alias bash='start bash'

# FIXME: Just fix this.
alias fix='there is something wrong with this

What I want is if I search for pattern TODO: it should only print result like this:

# TODO: Optimize this.
alias bash='start bash'

Is this possible?

  • 1
    Can there be multiple TODO sections, and what should the output be in that case? – Stephen Harris Nov 5 '18 at 18:15
  • yes, there can be multiple match of the same pattern, in that case i want to only print the first hit if it possible with ambiguous search. – cevhyruz Nov 6 '18 at 2:52
3

Awk in paragraph mode:

awk -vRS= '/TODO:/' file
| improve this answer | |
0

Duplicate of https://stackoverflow.com/questions/13534306/how-can-i-set-the-grep-after-context-to-be-until-the-next-blank-line

but you'd need sed as suggested in the post:

sed -n '/pattern/,/^$/p' file

| improve this answer | |
-1

grep solution.

grep -zoP '(?s)^# TODO.*^$' file
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.