首页 > 解决方案 > 使用 gnu-parallel 处理文件内容

问题描述

我有一个文件,内容如下:

/path/to/file1
/path/to/file2
/path/to/file3
/path/to/file4

我想使用该gnu-parallel实用程序在每一行上并行运行一个命令,我知道该实用程序支持使用::::. 我不确定的是我应该将哪些参数传递给 gnu-parallel 以拆分文件内容\n并并行处理?

标签: bashgnu-parallel

解决方案


这是man parallel

NAME
       parallel - build and execute shell command lines from
       standard input in parallel

SYNOPSIS
       parallel [options] [command [arguments]] < list_of_arguments
       [...]

这是这种调用形式的示例:

$ cat mylist.txt
/path/to/file1
/path/to/file2
/path/to/file3
/path/to/file4

$ parallel 'echo "I am processing:" {}' < mylist.txt
I am processing: /path/to/file1
I am processing: /path/to/file2
I am processing: /path/to/file3
I am processing: /path/to/file4

推荐阅读