After matching the last "Constrained" I want to print the 6th to 10th line:
This is what I've tried:
awk '/Constrained/ { print ; for(n=6; n<10; n++) { getline ; print } }' filename
But doesn't work. I was thinking of using tail -5 to get only the last 5 lines. (LInes 6 to 10 of only the last match)
You can test it with this:
************************** Constrained Symmetrised Forces **************************
* *
* Cartesian components (eV/A) *
* -------------------------------------------------------------------------------- *
* x y z *
* *
* O 1 -0.03440 -0.03440 0.00000 *
* O 2 0.03440 0.03440 -0.00000 *
* O 3 -0.03440 0.03440 -0.00000 *
* O 4 0.03440 -0.03440 0.00000 *
* Ti 1 0.00000 0.00000 0.00000 *
I should get the lines that start with O and end with Ti. But throughout the file there are several "constrained"