Carles
Carles

Reputation: 17

How to delete lines not starting with white space and integer

I have a text file and I would like to delete all lines (including blank lines) that don't start with either 5,4 or 3 white space and an integer value.

So far I have manually deleted the first part of the text file and then I have identified some words on lines that I want also to delete and used grep:

grep -v "iter" out_modif.log > out_modif2.log
grep -v "Stabilizing" out_modif2.log > out_modif3.log
grep . out_modif3.log > out_modif4.log

and so on.

I have tried

grep -v "^[!0-9]" out.log > out2.log

but did not work (I guess because of the white spaces preceding the integer)

exemple of a part of the input text file:

Initialize using the hybrid initialization method.

Checking case topology... 
-This case has both inlets & outlets 
-Pressure information is available at the boundaries

    iter        scalar-0        scalar-1

    1       1.000000e+00    0.000000e+00
    2       8.345726e-04    0.000000e+00

  iter  continuity  x-velocity  y-velocity  z-velocity

     1  1.0000e+00  1.6601e-02  7.6482e-03  1.7253e-02

I expect the output of the command to be a file with only:

 1  1.0000e+00  1.6601e-02  7.6482e-03  1.7253e-02

(the other lines containing an integer have TAB instead of white space)

Upvotes: 0

Views: 48

Answers (1)

tink
tink

Reputation: 15204

I called my file with your input carles:

grep -P '^ {3,5}[0-9]+[[:space:]]' carles
    1  1.0000e+00  1.6601e-02  7.6482e-03  1.7253e-02

Upvotes: 1

Related Questions