2

I'm reading through a very large web service log, and I want to pull a single line out from the file, and write it to a new file.

The log lines consist of web service request XML, so they are long and unwieldy.

1 Answer 1

5

w can operate on ranges, so you can do:

:.w foo

From :help :w:

:[range]w[rite]! [++opt] {file}
                    Write the specified lines to {file}.  Overwrite an
                    existing file.

Any range would do, so the following will write lines N-M inclusive to file foo:

:N,Mw foo

The . in the first command stands for the current line. See :help :range for more information.

2
  • 1
    Thanks, this command worked ... :34908,34914w ~/webservicelogextract.txt
    – roblogic
    Mar 17, 2015 at 1:58
  • 2
    Note that most (all?) commands that take a range also work from Visual mode. When you type : from Visual mode, it automatically inserts '<,'> for you. This is a range using special marks that refer to the start and end of a Visual selection. Leave the inserted range and type in your command (it will look like :'<,'>w webservicelogextract.txt).
    – tommcdo
    Mar 17, 2015 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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