我将如何在这个 while 循环中使用 GNU Parallel?

Pro*_*iat 12 shell-script files gnu-parallel

所以我有一个while循环:

cat live_hosts | while read host; do \
    sortstuff.sh -a "$host" > sortedstuff-"$host"; done
Run Code Online (Sandbox Code Playgroud)

但这可能需要很长时间。我将如何在这个 while 循环中使用 GNU Parallel?

don*_*sti 13

您不使用 while 循环。

parallel "sortstuff.sh -a {} > sortedstuff-{}" <live_hosts
Run Code Online (Sandbox Code Playgroud)

请注意,如果您的live_hosts(eg /some/dir/file) 中有路径,这将不起作用,因为它会扩展到sortstuff.sh -a /some/dir/file > sortedstuff-/some/dir/file(导致no such file or directory); 对于这些情况{//}{/}请使用和(有关详细信息,请参阅gnu-parallel手册):

parallel "sortstuff.sh -a {} > {//}/sortedstuff-{/}" <live_hosts
Run Code Online (Sandbox Code Playgroud)