linux - 如何选择目录中的所有文件并运行命令

标签 linux find

我想从工具运行命令来合并我的文件

http://snpeff.sourceforge.net/SnpSift.html#Split

java -jar ~/snpEff_latest_core/snpEff/SnpSift.jar split -j file1.vcf file2.vcf file3.vcf ...  > huge.out.vcf

我有 400 多个文件,所以一个一个地输入可能是错误的。

我试过这样的东西

 find -name "*.vcf" | java -jar ~/snpEff_latest_core/snpEff/SnpSift.jar split -j > comb.vcf

这是我遇到的错误

Error: Cannot 'join' less than two files.
SnpSift split -j
SnpSift version 4.1k (build 2015-09-07), by Pablo Cingolani

Usage: java -jar SnpSift.jar splitChr [-j] [-l <num>] file.vcf [file_2.vcf ... file_N.vcf]
Options:
    -j         : Join all files in command line (output = STDOUT).
    -l <num>   : Split by 'num' lines.
    Default    : Split by chromosome (one file per chromosome).

我在其他工具上使用过这个“find -name”,它似乎有效。

所以我的问题是,如何选择目录中的所有文件并运行命令。

最佳答案

你可以试试:

java -jar ~/snpEff_latest_core/snpEff/SnpSift.jar split -j file*.vcf

Bash 会将文件*.vcf 展开为当前目录中与文件*.vcf 匹配的所有文件。

请注意 linux 对命令的长度有最大限制(大约 3MB)。

如果你想使用查找(给你更细粒度的选择),你可以使用这样的东西:

find . -exec java -jar ~/snpEff_latest_core/snpEff/SnpSift.jar split -j {} \+

这里的“{}”替换为find找到的文件,\+表示:

the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end

关于linux - 如何选择目录中的所有文件并运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33645375/

相关文章:

linux - 未定义 JAVA_HOME 环境变量。如何在 ubuntu 12.04 中修复?

c++ - 我怎样才能在 wxWidgets 中找到一个 sizer?

Linux 命令 - 根据扩展名和创建日期查找文件

find - 如何在 capybara 中使用 fill_in 和 find (如果可能)

collections - 在数组列表中收集 findall

linux - 在 Linux 中递归添加 bash 脚本作为命令?

c++ - 如何在大型 Linux 应用程序中以编程方式设置 "yank the network cable"?

linux - 如何将多个txt文件加入到基于列?

linux - mkimage 中未提供 arm64 支持

arrays - bash:在查找函数中使用参数填充数组