Gary Johnson wrote:
On 2007-03-31, Auro Ashish Saha <[EMAIL PROTECTED]> wrote:
Hello Antoine,

Thanks for your post. I tried both the options but i could not get any
result. I am using gvim. Please help.

Regards,

Auro Ashish Saha.
Auro Ashish Saha wrote:
Hello,

Please help me to remove alternate lines from a text file.

000000 00000
123456 99999
999999 99999
123445 99999

I want to delete the line 1, 3, 5 and so on. What are the commands to be
used. Thanks for help in advance.

Regards,

Auro Ashish Saha.



Method I:

        q"ddjjq
        <count>@"

where <count> is equal to the number of lines still to be deleted

One problem with this is that it attempts to store a sequence of normal-mode commands into the " register, which is the unnamed register, but then deletes the first line into this same register.

The other problem with it is that it moves the cursor too many times: once the first line has been deleted with dd, the cursor automatically moves to the next line, so only one j is needed to get to the next line to be deleted.

This version will work:

    qqddjq
    <count>@q

Note that it uses the q register instead of the " register. Also, if you don't want to try to figure out what <count> should be, and if you don't want to remove a huge number of lines, you can execute the recorded commands the first time after you record them with this command:

    @q

and every subsequent time with this command:

    @@

That way, once you've recorded the command and executed it once from the q register, you can just hold your finger on the @ key and watch the lines disappear. As you get close to the bottom of your file, you can start slowing down and typing just two @'s at a time.

Method II (all on one line if typed on the Vim command-line):

     :let i=1 | while i <= line('$') | if (i % 2) | exe i . "delete" |
endif |
endwhile

It looks as though Tony left out part of Method II: i is never incremented. I modified it as shown below (added "let i += 1 |")and verified that it works.

    :let i=1 | while i <= line('$') | if (i % 2) | exe i . "delete" | endif | 
let i += 1 | endwhile

HTH,
Gary


Duh. My bad. Apparently I was lacking sleep when I typed that email.

Best regards,
Tony.
--
The primary purpose of the DATA statement is to give names to
constants; instead of referring to pi as 3.141592653589793 at every
appearance, the variable PI can be given that value with a DATA
statement and used instead of the longer form of the constant.  This
also simplifies modifying the program, should the value of pi change.
                -- FORTRAN manual for Xerox Computers

Reply via email to