I have a file with the following structure:[Term]id: GO:0000001name: mitochondrion inheritancenamespace: biological_processdef: The distribution of mitochondria, including the mitochondrial genome, into daughter cells after mitosis or meiosis, mediated by interactions between mitochondria and the cytoskeleton. [GOC:mcc, PMID:10873824, PMID:11389764]synonym: mitochondrial inheritance EXACT []is_a: GO:0048308 ! organelle inheritanceis_a: GO:0048311 ! mitochondrion distributionThis structure is repeated several times, like a dictionary. Each definition starts with [Term] and it's separated from the following by an empty newline; not every definition ends with a line starting with is_a.I want to grep some terms and retrieve the whole definition, so from [Term] to the empty newline; i.e., the structure example shown before could be the result of grep -i mitochondria myfile. How do I do it? The number of lines of each definition is not fixed, and the match could be at any point of the definition. I'm not sure that grep is the right tool to do it; the thing is that I want to match several words at once, so I started using grep -i -e match -e someothermatch. Is there some regex that does the trick?I work with Cygwin in a Windows environment, and apparently it supports PCRE.
Extract all lines from a word to another with my match in between
text processing;grep;cygwin
From your description (emphasis mine):Each definition starts with [*Term*] andit's separated from the following by an empty newlineAwk, when called with a null RS (RS='') splits a file on empty lines.It is also capable of selecting based on strings:$ var=someothermatch$ awk -v RS='' -v var=$var '$0~var{print}' infileShould work to get the whole paragraph that match.From awk manual:If RS is set to the null string, then records are separated by blank lines.  When RS is set to the null string,  the  newline character always acts as a field separator, in addition to whatever value FS may have.