Question: I need to grep a file from a line containing `Pattern A` to a first empty line. 
I used `awk` but I don't know how to code this empty line.

```
cat ${file} | awk '/Pattern A/,/Pattern B/'

```

Answer: 
Using `sed`: 

```
sed -n '/PATTERN/,/^$/{/^$/q;p;}' file

```

Using `regex` range, you define your range from the `PATTERN` to blank line (`/^$/`). When you encounter a blank line, you quit else you keep printing. 

Using `awk`: 

```
awk '/PATTERN/{p=1}/^$/&&p{exit}p' file 

```

You enable a flag when you encounter your `PATTERN`. When you reach a blank line and flag is enabled, you exit. If not, you keep printing. 

Another alternate suggested by [devnull](https://stackoverflow.com/questions/23831767/grep-awk-a-file-from-a-to-first-empty-line/23831984?noredirect=1#comment36672882_23831984) in the comments is to use `pcregrep`: 

```
pcregrep -M 'PATTERN(.|\n)*?(?=\n\n)' file

```
Never use

```
/foo/,/bar/

```

in awk unless you want to get from the first occurrence of "foo" to the last occurrence of "bar" as it makes trivial jobs marginally briefer but even slightly more interesting requirements require a complete re-write.

Just use:

```
/foo/{f=1} f{print; if (/bar/) f=0}

```

or similar instead.

In the case the awk solution is:

```
awk '/pattern/{f=1} f{print; if (!NF) exit}' file

```