Monday, July 30, 2012

Re: ex large file

On 30/07/12 21:03, Tony Mechelynck wrote:
> On 30/07/12 20:24, Gary Johnson wrote:
>> On 2012-07-30, Enda wrote:
>>
>>> On July 30, 2012 6:09 PM, Gary Johnson wrote:
>>
>>>> On 2012-07-30, Enda wrote:
>>>>> Is there a way to empty the contents of a large file? The
>>>>> below doesn't work:
>>>>>
>>>>>
>>>>> $ ex -s largefile -c '1,$d' -c wq
>>>>>
>>>>> Killed
>>>>
>>>> I don't know why that is failing. Ben had some good questions. But
>>>> if you just want to empty the file, use this from your shell:
>>>>
>>>> $ > largefile
>>
>>> 'echo "" > filetowipe' would be a new file, I want to edit the same
>>> file.
>>
>> I'm not following you. I didn't suggest redirecting to a new file.
>> I suggested redirecting to the same file name you used in your
>> example. Further, I didn't suggest using echo--I suggested simply
>> this command (shown this time without the shell prompt):
>>
>> > largefile
>>
>> where 'largefile' is the name of the file you wish to empty.
>>
>>> I don't want to crash my desktop again. I think the fact that ex
>>> creates .swp and .swo files might contribute to the problem.
>>
>> You might find this article of help:
>>
>> http://vim.wikia.com/wiki/Faster_loading_of_large_files
>>
>> If you can do anything with Vim that will crash your desktop, that
>> would be a serious bug in Vim. Does it happen with any file over
>> some size? How large was your 'largefile'?
>>
>> Regards,
>> Gary
>>
>> P.S.
>>
>> Note that the convention on this list it to not top-post. See the
>> footer of every message on this list.
>>
>
> Another possibility, maybe better known, would be
>
> cp /dev/null largefile
>
> on Unix etc., or
>
> copy NUL largefile
>
> on Dos/Windows. Neither of these uses Vim, you type them directly at the
> shell prompt (for bash or cmd.exe or whatever).
>
>
> If the filesize is 5 GiB you would need that much memory for Vim to edit
> the file, even if the only edit operation were ":%d | wq". Unless you
> have a 64-bit machine with a huge lot of RAM (maybe at least twice as
> much as I have), I don't recommend it.
>
> Additionally, depending on the state of the 'backupcopy' option, Vim may
> rename the original file, create a copy under the original name, then if
> all went well delete the original. This would require as least as much
> empty disk space as the file size, and in the same disk partition. This
> would also not be "the same file" but "a new file of the same name".
>
>
> Best regards,
> Tony.

P.S. If you are dead set on deleting the file by using Vim (and even
without the :! or system() "external" commands), you can:

vim # opens Vim on an empty buffer
:saveas! largefile " overwrites the large file
:q


Best regards,
Tony.
--
The sooner you make your first 5000 mistakes, the sooner you will be
able to correct them.
-- Nicolaides

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment