Using just shell script, how to search a text file and list all whole blocks of lines that has inside some text (simple grep criteria).
The text file has blocks of lines separated by "-----------------"
(precisely, each block start with "\n\n\n--------------------"
... about 50 chars "-").
A sample could be:
-------------------------------
Abracadabra, blablablalbalba
blablablabla, banana
-------------------------------
Text, sample text, sample text, sample text
Text, sample text, sample text, sample text
Text, sample text, sample text, sample text
Text, sample text, sample text, sample text
-------------------------------
Text, sample text, sample text, sample text
banana. Sample text, sample text, sample text, sample text
Text, sample text, sample text, sample text
Lets consider the word "banana" the search criteria. So, the blocks listed would be:
-------------------------------
Abracadabra, blablablalbalba
blablablabla, banana
-------------------------------
Text, sample text, sample text, sample text
banana. Sample text, sample text, sample text, sample text
Text, sample text, sample text, sample text
EDIT:
Testing answers to try awk, like: awk 'BEGIN{RS="\n------------"}/INFO/{print}'
where INFO is what was searched for. I cannot get the whole block. So, follows a real sample and the result:
A REAL SAMPLE (including the first 3 new lines):
------------------------------------------------- Diretório separado do nome o arquivo: adis, IWZLM (/home/interx/adis/src/IWZLM.SRC) Gerando rotina em linguagem C: (yla5 adis IWZLM -if) .INFO =>Rotina BLOQUEADA (status 'M'): Geracao ignorada (use -is para ignorar checagem do status) [ OK-I ] IWZLM (adis) - Lista lay: Geracao ignorada do codigo em C. ------------------------------------------------- Diretório separado do nome d arquivo: adis, ADISA (/home/interx/adis/src/ADISA.SRC) Gerando rotina em linguagem C: (yla5 adis ADISA -if) .ERRO: Falha inesperada Compilando o programa: (ycomp adis ADISA -exe adis/exe/ADISA.temp.exe ) adis/exe/ADISA.temp.exe => adis/exe/ADISA [ OK ] ADISA (adis) - Menu A : Gerada e compilada com sucesso. ------------------------------------------------- Diretório separado do nome o arquivo: adis, ADISD1 (/home/interx/adis/src/ADISD1.SRC) Gerando rotina em linguagem C: (yla5 adis ADISD1 -if) .ATENCAO: Definicao nao localizada Compilando o programa: (ycomp adis ADISD1 -exe adis/exe/ADISD1.temp.exe ) adis/exe/ADISD1.temp.exe => adis/exe/ADISD1 [ OK ] ADISD1 (adis) - Menu : Gerada e compilada com sucesso.
I cannot get the whole block, just the line containing "INFO", like a ordinary grep, either setting or not ORS:
$ cat file | awk 'BEGIN{RS="\n------------"}/INFO/{print}'
.INFO =>Rotina BLOQUEADA (status 'M'): Geracao ignorada (use -is para ignorar checagem do status)
NOTES: It is the awk from AIX 7.1, not gawk.