There is file with lines, say
Sec #1 SectionA
..................
..................
..mypattern.......
..................
Sec #2 SectionB
..................
.......mypattern..
..................
.
.
.
Sec #n SectionN
This pattern will only be present in some sections and I would like to search on mypattern
and get the section names (SectionA, SectionB etc..) containing the mypattern
.
How to get it? I have tried with grep
, sed
, pcre2grep
but wasn't able to get names.
awk '/Sec/,/mypattern
grep -oz 'Sec.*mypattern'
pcre2grep -M 'Sec.*(\n|.)*?mypattern'
Clarifications:
mypattern
is just a string, no regex