I am trying to extract lines containing a certain string also 4 lines before it (just the fourth line not the ones in between). Right now I can get the line itself;
grep -n "my string" myfile.out > output.txt
I can also get the lines before it, but not that specific one, all the four preceding lines;
grep "my string" -B 4 myfile.out > output.txt
Let's take this example:
! CREEK
FLUX 6739, 6670, 6640, 6672, 6582, 6583, 6548, 6576, 6570 &
656565
***
*** THE SUM OF SPECIFIED: -1.192451
*** THE AVERAGE: -6.2760599E-02
*** THE MAXIMUM: 0.000000
*** THE MINIMUM: -0.4294980
*** THE SUM OF POSITIVE: 0.000000
*** THE SUM OF NEGATIVE: -1.192451
I want this output:
! CREEK
*** THE SUM OF SPECIFIED: -1.192451
I would appreciate windows-batch-file solution or PowerShell as well.