Question: I have the following text in my file

```
---BEGIN TEXT---
any text1
anytext2
anytext3
---END TEXT---
---BEGIN TEXT---
any text4
any text5
---END TEXT---

```

I want to remove the **2nd** text block from `"---BEGIN TEXT---"` to `"---END TEXT---"`

How I can make that with a linux command

So my file will contains only:

```
---BEGIN TEXT---
any text1
anytext2
anytext3
---END TEXT---

```

I know how to remove the 1st block with the following command:

```
sed -n '/BEGIN TEXT/,/END TEXT/{p;/PAT2/q}' file.txt

```

How I can modify my `sed` comand to remove the 2nd part and not the first part? or use another command like `awk` ?

Answer: 
With GNU awk for multi-char RS and RT:

```
$ awk -v RS='---END TEXT---\n' '{ORS=RT} NR==1' file
---BEGIN TEXT---
any text1
anytext2
anytext3
---END TEXT---

$ awk -v RS='---END TEXT---\n' '{ORS=RT} NR!=1' file
---BEGIN TEXT---
any text4
any text5
---END TEXT---

$ awk -v RS='---END TEXT---\n' '{ORS=RT} NR==2' file
---BEGIN TEXT---
any text4
any text5
---END TEXT---

```
This might work for you (GNU sed):

```
sed -r '/---BEGIN/{:a;N;/^---END/M!ba;x;s/^/x/;/^x{2}$/{x;d};x}' file

```

Gather up the lines between `---BEGIN` and `---END` and then increment a counter in the hold space (HS). If the counter is 2 delete the collection otherwise print as normal.