I have managed to do this with a super long find-replace but I'm sure there's a simpler way:
I have a file of the form:
E01 2017 10 24 00 00 00-1.90001e-04-8.79280e-12 0.00000e+00
3.20000e+01 8.53750e+01 2.90408e-09 3.04855e+00
4.08463e-06 3.01205e-04 1.49385e-06 5.44061e+03
1.72800e+05 6.14672e-08-1.45096e+00-7.45058e-09
9.95466e-01 3.22187e+02-2.16382e+00-5.72952e-09
7.50018e-11 2.58000e+02 1.90000e+03 0.00000e+00
3.12000e+00 0.00000e+00-4.49424e-09 0.00000e+00
1.73500e+05 0.00000e+00 0.00000e+00 0.00000e+00
E01 2017 10 24 00 00 00-1.90001e-04-8.79280e-12 0.00000e+00
3.20000e+01 8.53750e+01 2.90410e-09 3.04855e+00
4.08460e-06 3.01205e-04 1.49380e-06 5.44061e+03
1.72800e+05 6.14672e-08-1.45100e+00-7.45058e-09
9.95470e-01 3.22187e+02-2.16380e+00-5.72952e-09
7.50020e-11 5.21000e+02 1.90000e+03 0.00000e+00
0.00000e+00 0.00000e+00-4.49420e-09-5.35510e-09
1.73400e+05 0.00000e+00 0.00000e+00 0.00000e+00
E02 2017 10 24 00 00 00-5.65248e-06 9.24880e-13 0.00000e+00
3.20000e+01 1.05375e+02 2.89100e-09-7.19798e-01
4.93710e-06 2.56068e-04 2.77200e-06 5.44061e+03
1.72800e+05 4.84287e-08-1.49240e+00-8.75443e-08
9.95490e-01 2.94906e+02-1.54180e+00-5.75452e-09
1.30070e-10 2.58000e+02 1.90000e+03 0.00000e+00
0.00000e+00 0.00000e+00-6.99620e-09 0.00000e+00
1.73500e+05 0.00000e+00 0.00000e+00 0.00000e+00
...
Each line starting with E
represents the beginning of a "block". All blocks are 8 lines long, and the width of the columns is fixed for the whole file. I want to delete a block if the second element of the sixth line of the block is (not) 2.58000e+02
.
So after deleting all blocks which do have 2.58000e+02
as the second element of their sixth line I would expect:
E01 2017 10 24 00 00 00-1.90001e-04-8.79280e-12 0.00000e+00
3.20000e+01 8.53750e+01 2.90410e-09 3.04855e+00
4.08460e-06 3.01205e-04 1.49380e-06 5.44061e+03
1.72800e+05 6.14672e-08-1.45100e+00-7.45058e-09
9.95470e-01 3.22187e+02-2.16380e+00-5.72952e-09
7.50020e-11 5.21000e+02 1.90000e+03 0.00000e+00
0.00000e+00 0.00000e+00-4.49420e-09-5.35510e-09
1.73400e+05 0.00000e+00 0.00000e+00 0.00000e+00
After deleting all blocks whose second element in the sixth line is not 2.58000e+02
I would expect:
E01 2017 10 24 00 00 00-1.90001e-04-8.79280e-12 0.00000e+00
3.20000e+01 8.53750e+01 2.90408e-09 3.04855e+00
4.08463e-06 3.01205e-04 1.49385e-06 5.44061e+03
1.72800e+05 6.14672e-08-1.45096e+00-7.45058e-09
9.95466e-01 3.22187e+02-2.16382e+00-5.72952e-09
7.50018e-11 2.58000e+02 1.90000e+03 0.00000e+00
3.12000e+00 0.00000e+00-4.49424e-09 0.00000e+00
1.73500e+05 0.00000e+00 0.00000e+00 0.00000e+00
E02 2017 10 24 00 00 00-5.65248e-06 9.24880e-13 0.00000e+00
3.20000e+01 1.05375e+02 2.89100e-09-7.19798e-01
4.93710e-06 2.56068e-04 2.77200e-06 5.44061e+03
1.72800e+05 4.84287e-08-1.49240e+00-8.75443e-08
9.95490e-01 2.94906e+02-1.54180e+00-5.75452e-09
1.30070e-10 2.58000e+02 1.90000e+03 0.00000e+00
0.00000e+00 0.00000e+00-6.99620e-09 0.00000e+00
1.73500e+05 0.00000e+00 0.00000e+00 0.00000e+00
My attempt
To delete the blocks which contain 2.58000e+02
First delete the block themselves with:
:%s/^E[0-9 .e+-]\+\n\([0-9 .e+-]\+\n\)\{4}[ ]\+[0-9.e+-]\+ 2.58000e+02\([0-9 .e+-]\+\n\)\+//g
Then remove the blank lines which remain after the blocks that have been preserved:
:%s/\n^[ ]\{}$//g
To delete the blocks which do not contain 2.58000e+02
:
This one was tougher. What I did is store the result of the previous command in a separate file, and from terminal perform the diff between the original file and the new file, and keep the lines which are in the original one and not the second one. This however requires leaving ViM.
Is there a simpler way to achieve these two things?