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?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
cevhyruz
  • 417
  • 4
  • 15

3 Answers3

3

Awk in paragraph mode:

awk -vRS= '/TODO:/' file
steeldriver
  • 78,509
  • 12
  • 109
  • 152
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

sla3k
  • 429
  • 2
  • 6
-1

grep solution.

grep -zoP '(?s)^# TODO.*^$' file
steve
  • 21,582
  • 5
  • 48
  • 75