Имею текстовый файл в таком формате:
[Term]
id: HP:0000006
name: Autosomal dominant inheritance
alt_id: HP:0001415
alt_id: HP:0001447
alt_id: HP:0001448
alt_id: HP:0001451
alt_id: HP:0001455
alt_id: HP:0001456
alt_id: HP:0001463
def: "A mode of inheritance that is observed for traits related to a gene encoded on one of the autosomes (i.e., the human chromosomes 1-22) in which a trait manifests in heterozygotes. In the context of medical genetics, an autosomal dominant disorder is caused when a single copy of the mutant allele is present. Males and females are affected equally, and can both transmit the disorder with a risk of 50% for each child of inheriting the mutant allele." [HPO:curators]
synonym: "Autosomal dominant" EXACT []
synonym: "Autosomal dominant form" RELATED [HPO:skoehler]
synonym: "Autosomal dominant type" RELATED [HPO:skoehler]
xref: SNOMEDCT_US:263681008
xref: UMLS:C0443147
is_a: HP:0000005 ! Mode of inheritance
[Term]
id: HP:0000007
name: Autosomal recessive inheritance
alt_id: HP:0001416
alt_id: HP:0001526
def: "A mode of inheritance that is observed for traits related to a gene encoded on one of the autosomes (i.e., the human chromosomes 1-22) in which a trait manifests in homozygotes. In the context of medical genetics, autosomal recessive disorders manifest in homozygotes (with two copies of the mutant allele) or compound heterozygotes (whereby each copy of a gene has a distinct mutant allele)." [HPO:curators]
synonym: "Autosomal recessive" EXACT []
synonym: "Autosomal recessive form" RELATED [HPO:skoehler]
synonym: "Autosomal recessive predisposition" RELATED []
xref: SNOMEDCT_US:258211005
xref: UMLS:C0441748
xref: UMLS:C4020899
is_a: HP:0000005 ! Mode of inheritance
Я хотел бы выбрать и перенести 2 строки (первая начинается с «name:», а вторая с «def:» и ограничена двойными кавычками) из каждой группы, начиная с [Term], чтобы была создана следующая таблица:
column 1 column 2
name | definition
Autosomal dominant inheritance | A mode of inheritance that is observed for traits related to a gene encoded on one of the autosomes (i.e., the human chromosomes 1-22) in which a trait manifests in heterozygotes. In the context of medical genetics, an autosomal dominant disorder is caused when a single copy of the mutant allele is present. Males and females are affected equally, and can both transmit the disorder with a risk of 50% for each child of inheriting the mutant allele.
Вот моя попытка:
gawk 'BEGIN{RS="[Term]"}{match($0, /^name:/, a) match($0, /^def:/, b) print a[1] , b[1]}' rows.txt > columns.txt