Saturday, September 4, 2021

Re: How to replace pattern with shell command's output using matched pattern

On 04.09.21 11:15, Lifepillar wrote:
> Use case at hand: replace Unix timestamps with date/time in a log file:
>
> [1630720618] unbound[63495:0] info: 127.0.0.1 foo.bar.com AAAA IN
> [1630720618] unbound[63495:1] info: 127.0.0.1 foo.bar.com A IN
> ...
>
> The shell command I'd apply is `date -r <timestamp>`. How would you
> perform the substitution?

:%s_^\[\(\d\+\)_\="[" . systemlist("date -r " . submatch(1))[0]_

Alternatively, without using an external command:

:%s_^\[\(\d\+\)_\="[" . strftime("%c", submatch(1))_

Bye, Andreas

--
--
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/ceb43426-f262-ff90-3847-58e4205d9161%40gmail.com.

No comments:

Post a Comment