Sunday, July 12, 2020

Using :g to filter lines through an external command

Hi all,

Assume I have a file (or just a buffer) with the contents:
echo Hello from /bin/sh
test1
test2
test3
---end-file---

:1!sh does what I would expect: it passes "echo Hello from /bin/sh" as
input to the shell, which executes the line as a command, and the line
is replaced with "echo"'s output "Hello from /bin/sh".

:g/test/!nl does not do what I expected (and wanted). Instead of
piping the matched lines through the "nl" command, it appears to start
an interactive shell.

:g/test/.!nl works better, but executes "nl" once for *each* of the
matched lines, which are replaced with the following:
1 test1
1 test2
1 test3
---end-quote---

Is there a solution to this?

-Albert.

--
--
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/CALPW7mQAEUZ%2BNp-BYFcCBmw%3D2K-%3DnJOr8Johg0Uc5zkCUyOW3Q%40mail.gmail.com.

No comments: