Extract few content from a huge list of files

I have a huge list of files (about 300,000) which have a pattern like this.

.I 1
.U
87049087
.S
Am J Emerg
.M
Allied Health Personnel/*; Electric Countershock/*;
.T
Refibrillation managed by EMT-Ds:
.P
ARTICLE.
.W
Some patients converted from ventricular fibrillation to organized rhythms by defibrillation-trained ambulance technicians (EMT-Ds) will refibrillate before hospital arrival. The authors analyzed 271 cases o.
.A
Stults KR.

I want to extract only two fields from this file, and store in a separate file. So my output should be:

.U
87049087
.W
Some patients converted from ventricular fibrillation to organized rhythms by defibrillation-trained ambulance technicians (EMT-Ds) will refibrillate before hospital arrival. The authors analyzed 271 cases o.

What I have been trying for sometime now is to first extract the line after

, using the following code:

awk '/\.U/{c=2}c&&c--' file

and then I used this code in another step to extract the pattern after

:

. But these two codes are not at all proving to be effective for me. Is there any better way of extracting those contents? I am using Linux with BASH.

You were very close, just change:

awk '/\.U/{c=2}c&&c--' file

to:

awk '/\.[UW]/{c=2}c&&c--' file
1 Like