I have a file A.tsv
(field separator = \t
):
for Research Use Only
[Header]
Test Name Il
Run ID 2102
Run Date 2021-02-04
Report Date/Time 2021-02-05 08:48
Instrument Serial
Flow Cell ID
Software Version
[Quality Control]
Lane 1,2,3,4 PASS
Lane 1,2,3,4 Index Set 1 PASS
[Patient Sample Results]
Sample ID Internal Control Result Consensus Sequence Lane Index Set Index ID
207 Pass Not Available 1,2,3,4 1 UDP0001
205 Pass Not Available 1,2,3,4 1 UDP0002
[Control Sample Results]
Sample ID Control Type Human Control SARS-CoV-2 Lane Index Set Index ID
CONTROL-POS Positive Control Not Detected Detected 1,2,3,4 1 UDP0008
I want to only print those line in a new file :
Sample ID Internal Control Result Consensus Sequence Lane Index Set Index ID
207 Pass Not Available 1,2,3,4 1 UDP0001
205 Pass Not Available 1,2,3,4 1 UDP0002
CONTROL-POS Positive Control Not Detected Detected 1,2,3,4 1 UDP0008
So I want to print the lines after [Patient Sample Results]
and [Control Sample Results]
, but only print the header line once.
That file is a subsampling and it can't be hardcoded be using line number.
So I tried somthing like :
awk '/Patient Sample Results/{getline; print}' A.tsv > data_info.tsv
But it prints only the line after the first pattern. Do you have a solution for my problem?
[ ... ]
a "section title", you want to print all sections starting with[Patient Sample Results]
, excluding the section title, and including the header line, but only once? Are there further sections after the two yuo want printed, and do you want to exclude any of them (or just print all)? Is the "header line" always the first one after the section title? Are there empty lines that need to be treated specially? Also, can we assume that all sections are separated by exactly one empty line?