2

I have a file (around 1.6 million lines) which formatted like this:

-0.00697468 0 -1.95966e-49 101325 -3.06381  
-0.00697468 0 -1.95966e-49 101325 -3.06381  
-0.00697468 0 -1.95966e-49 101325 -3.06381  
. . .  

After some thousand lines, the format will be changed (no minus sign on the first character), like this:

0.453945 -2.14126e-54 3.40152e-49 101325 214.355  
0.453945 -2.14126e-54 3.40152e-49 101325 214.355  
0.453945 -2.14126e-54 3.40152e-49 101325 214.355  
. . .

So, how to delete the entire line, after the first whitespace on every line? I have tried to search but couldn't get any answer that I want. Thanks! (Note: some lines have different number of character, hence that I cannot simply delete some characters from the end of the line on every line)

3

The two commands below will reduce every line to the first sequence of non-whitespace character followed by a space:

from
0.453945 -2.14126e-54 3.40152e-49 101325 214.355

to
0.453945 <-- space

But your question is a little confusing so I'm not sure I understood what you want.

With a substitution:

:%s/\(\S\+\s\).*/\1

With a macro:

:%normal! WD
3

If you wanted to delete entire line starting with a space, This pattern will be useful.

:g/^\s.*/d
  • g -global
  • ^ - start of the line
  • \s - space
  • .* - anything after that
  • d - delete

If you want the starting whitespace to remain, but delete the remaining content, you can use,

:%s/^\(\s\+\).*/\1/g

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.