I have a file which is having following content:
zdk
aaa
b12
cdn
dke
kdn
Input1: aaa
and cdn
Output 1:
aaa
b12
cdn
Input 2: zdk
and dke
Output 2:
zdk
aaa
b12
cdn
dke
I could use below commands to achieve:
grep -a aaa -A2 file # Output 1
grep -a aaa -A4 file # Output 2
But in the file I don't know what is the exact occurrence (position) of end string pattern (file is having 20000 rows)
How can I achieve this?
/foo/,/bar/
to define patterns. The specifics of the pattern (being at the end for example) are secondary.