Wednesday, September 29, 2010

Re: How to open filelist with pipe?

I was requested to forward this to the list. Comments after.

On Tue, 28 Sep 2010, Ole Tange wrote:

> find ./ -name *.html | xargs grep -l rapp_document
>
> ./file1
> ./file2
> ./file3
>
> How to open the filelist ? like  "vim file1 file2 file3"

If you have GNU Parallel http://www.gnu.org/software/parallel/

find . -type f | parallel -uXj1 vim

GNU Parallel is generally useful for other tasks. Watch the intro video:
http://www.youtube.com/watch?v=OpaiGYxkSuQ

/Ole


[My too-wordy comments]

In general, parallel seems like a cool complement to xargs. Its main
goal is to run things in parallel (hence the name) across CPU cores or
across different servers via SSH.

Dissecting the command-line above:

#generate filenames# | parallel -uXj1 vim

Like xargs, parallel can take its argument list on stdin.

-u = 'ungroup' output # prevents output from being 'grouped'. Since
parallel is designed to run things in parallel, its default output mode
is to not intermingle the various subprocesses' output.

-X = 'xargs with context replace' # --xargs mode (-m) allows the
argument {} to be replaced with the input list. By default, if not
present, {} is appended to the argument list. (So `parallel -uXj1 vim`
is equivalent to `parallel -uXj1 {}`). 'xargs with context replace' is
like --xargs mode, except when {} appears mid-word the whole word is
repeated for each argument. This allows, e.g.:
seq 1 5 | parallel -uXj1 vim test-file-{}

-j1 = --jobs=1 # only run one job in parallel

--
Best,
Ben

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