-1

I have a file like this:

# a
some
lines

# b
some
more
lines

...

Say I want to match that # b paragraph:

# b
some
more
lines

I know that grep "# b" filename can match that line of pattern that I am interested in, but I don't know how to perform "match until blank line" action. Not sure if grep is better than sed or awk for this task. Help?

Jay Somedon
  • 1,068
  • 11
  • 27
  • first, by showing your attempts :) – fedorqui Oct 11 '16 at 08:28
  • 2
    As you mentioned `awk`, which is subjectively the best for this problem, you should see this: [How to select lines between two patterns?](http://stackoverflow.com/questions/38972736/how-to-select-lines-between-two-patterns). Blank line in `awk` can be matched with: `/^$/` where `^` is the beginning and `$` the end of string. – James Brown Oct 11 '16 at 09:32
  • @JamesBrown the accepted answer of that post is a really comprehensive one! – Jay Somedon Oct 12 '16 at 03:14

1 Answers1

0

Look at address ranges in sed:

sed -n '/^# b/,/^$/p'
Toby Speight
  • 27,591
  • 48
  • 66
  • 103