Thursday, November 18, 2021

Re: "Auto Yes" to Warnings On Save (Scriptability)

On Thu, Mar 26, 2020 at 07:59:38AM -0700, Joe Clark wrote:
> I am looking for a way to periodically remove the first N lines of a file,
> to implement a "quick and dirty" log file size management scheme.
>
> I have found that vi will effectively do this, and (somewhat surprisingly)
> the logging application seems to be okay with its log file being modified.

This is a very late response, but thought it might be good for the
archive in case someone was searching.

Several responders to the OP suggested sed or tail, which the OP didn't
want because he needed an in-place change that *didn't change the
inode*.

This is a good fit for... 'ed'! No, not me, ed the line editor.

$ seq 1000 > /tmp/nums.txt
$ wc -l /tmp/nums.txt
1000 /tmp/nums.txt
$ stat --printf "%i\n" /tmp/nums.txt
285890
$ printf '1,500d\nw\n' | ed /tmp/nums.txt
3893
2001
$ wc -l /tmp/nums.txt
500 /tmp/nums.txt
$ head -n 3 /tmp/nums.txt
501
502
503
$ tail -n 3 /tmp/nums.txt
998
999
1000
$ stat --printf "%i\n" /tmp/nums.txt
285890

You can see that ed is scriptable in a limited way (no loops or branches), but unlike vim doesn't assume interactive input, and saves in-place.

--
Ed Blackman

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/1637284311.08774c%40strabo.garrett.

No comments: