AWK solução:
awk 'NR==n{ if (/NEW Cell/) { f=0 } else print r ORS gr }
/NEW Cell/{ f=1; n=NR+2; r=$0; next }
f && n-NR==1 && /^grep /{ gr=$0; next }1' file
-
/NEW Cell/{ f=1; n=NR+2; r=$0; next }- ao encontrar linha comNEW Cell-
f=1= definir sinalizador ativof=1 -
n=NR+2- definencomo número máximo das seguintes linhas a serem processadas (2 próximas linhas) -
r=$0- capturando a linha -
next- pula para o próximo registro
-
-
f && n-NR==1 && /^grep /- ao encontrar a segunda linha (garantida porn-NR==1) que começa comgrepkeyword-
gr=$0; next- capturandogreplinha e pula para o próximo (terceiro) registro
-
-
NR==n{ if (/NEW Cell/) { f=0 } else print r ORS gr }- ao encontrar a terceira linha crucial (assegurada porNR==n)-
if (/NEW Cell/) { f=0 }- se a terceira linha na seção processada contiverNEW Cell- redefinir o processamento atual comf=0(todas as linhas capturadas anteriormente são ignoradas) -
else print r ORS gr- caso contrário, imprima todas as linhas capturadas anteriormente
-
A saída:
echo "NEW Cell"
grep "2557,20" out.2A25.20090308.64436.7.HDF.txt.text = 19.75 5.62 82.11 170
grep "2557,21" out.2A25.20090308.64436.7.HDF.txt.text = 24.34 5.58 82.13 120
grep "2558,22" out.2A25.20090308.64436.7.HDF.txt.text = 22.2 5.57 82.19 120
echo "NEW Cell"
grep "2560,22" out.2A25.20090308.64436.7.HDF.txt.text = 24.69 5.62 82.25 160
grep "2561,23" out.2A25.20090308.64436.7.HDF.txt.text = 24.74 5.60 82.30 120