Question: I am trying to find multiple specific lines in a file (species) and then print only the 5th line after each species name to a new file. I can do this fine for each species individually, but I am having trouble making a loop to go through each of the 1000 species I have in the document. For example:
awk 'c&&!--c;/species_1$/{c=5}' results.out > speciesnames
How can I make this command into a loop so that it does the following (iterates over every species in the file):
species 1, print 5th line to document titled speciesnames
species 2, print 5th line to document titled speciesnames
species n, print 5th line to document titled speciesnames
Any help would be appreciated. I have very little experience with loops. Thanks
Data structure example from results.out:
Query= species_1
length=341
Score
bits
Line 5, relevant info
description
description
description
description
description
description
description
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
nucleotides
data
data
data
data
data
data
Query= species_2
length=341
.......
Desired output into file speciesnames:
Line 5, relevant info for species 1
Line 5, relevant info for species 2
Line 5, relevant info for species n
descriptionandnucleotides20 times to try to describe your input is not nearly as useful as showing some actual data. Show at least 3 small blocks of representative data for sample input, one for each of 3 different species and each block being 5 or 6 lines. Also, show the output you want given that input.