awk para Ler entre duas cadeias de caracteres específicas e descartar o resto

0

Estou usando awk para apenas ler texto entre duas strings "Check" e "Result". Eu usei muitas variações encontradas na internet e ainda não consegui o resultado favorito. Eu tentei:

awk "/Check:/,/Result:/ {print}"  BMSCA209-040-transfer-report.18-Jun-2014.11:18.csv.tmp | more

Eu também tentei:

sed -n "/Check:/,/Result:/p" BMSCA209-040-transfer-report.18-Jun-2014.11:18.csv.tmp | more

E ainda não está conseguindo o que eu quero. Cada vez que eu entendo, é isso que eu recebo:

ata>    <data fieldName="Timepoint ID" value="B01 SCREENING"/>  <data fieldName="SQCSummary" value=" Nothing Submission Quality and Compliance Report - 201
4-06-03T14:30:00.547-07:00Check: Ensure slice thickness is between 2mm and 5mmResult: FailReason: Image(s) found with slice thickness out of range.   Instanc
e 1.2.840.113619.2.55.3.4094358250.93.1395417628.479.369 found with slice thickness out of range : 1.25   Instance 1.2.840.113619.2.55.3.4094358250.93.139541
7628.479.368 found with slice thickness out of range : 1.25   Instance 1.2.840.113619.2.55.3.4094358250.93.1395417628.479.367 found with slice thickness out
of range : 1.25   Instance 1.2.840.113619.2.55.3.4094358250.93.1395417628.479.366 found with slice thickness out of range : 1.25   Instance 1.2.840.113619.2.
55.3.4094358250.93.1395417628.479.365 found with slice thickness out of range : 1.25   Instance 1.2.840.113619.2.55.3.4094358250.93.1395417628.479.364 found
with slice thickness out of range : 1.25   Instance 1.2.840.113619.2.55.3.4094358250.93.1395417628.479.363 found with slice thickness out of range : 1.25   I
nstance 1.2.840.113619.2.55.3.4094358250.93.1395417628.479.362 found with slice thickness out of range : 1.25   Instance 1.2.840.113619.2.55.3.4094358250.93.
1395417628.479.361 found with slice thickness out of range : 1.25   Instance 1.2.840.113619.2.55.3.4094358250.93.1395417628.479.360 found with slice thicknes

Alguém tem outras sugestões?

    
por ryekayo 19.06.2014 / 13:59

2 respostas

1

com perl :

perl -l -0777 -ne 'print for /Check: (.*?)Result:/gs' < file

Com o GNU grep , o (quase) equivalente seria:

grep -zPo '(?s)Check: \K.*?(?=Result:)' < file

Ou com pcregrep :

pcregrep -Mo1 '(?s)Check: (.*?)Result:' < file

Saída:

Ensure Modality is the same for all images in a DICOM series.
Ensure SeriesDate is in the proper DICOM format (YYYYMMDD) for all images.
[...]
    
por 19.06.2014 / 15:14
1

Minha solução para o seu problema:

Use grep e manipulação de string bash assim:

RES="$(cat BMSCA209-040-transfer-report.18-Jun-2014.11:18.csv.tmp |  egrep -o 'Check.*Result')"
RES=${RES%Result}
RES=${RES#Check: }
echo $RES

Isso é:)

O resultado é:

Ensure slice thickness is between 2mm and 5mm
    
por 19.06.2014 / 14:53

Tags