【问题标题】:Looping through all the inputs in a directory and creating output directories with the input name循环遍历目录中的所有输入并使用输入名称创建输出目录
【发布时间】:2014-12-05 14:57:08
【问题描述】:

我有一个包含 10 个不同文件的目录,我需要对所有文件运行相同的命令,但将结果保存在单独的目录中,这些目录是唯一的,我的输入文件名作为结果目录名。我知道我的问题类似于Looping through all the inputs and creating distinct output files,所以我尝试了以下代码:

cd /user/test

for i in *.txt
do 
   fastqc $i -o {$i}.out
done

我收到一个错误:

Specified output directory '{1.txt}.out' does not exist
Specified output directory '{2.txt}.out' does not exist

我想知道可能是什么问题,因为它在创建管道和工作流时会有所帮助。 谢谢!

【问题讨论】:

    标签: bash loops


    【解决方案1】:

    你外面有{},你需要使用:

    cd /user/test    
    for i in *.txt; do
       fastqc "$i" -o "${i}.out"
    done
    

    或者只是:

    for i in *.txt; do
       fastqc "$i" -o "$i.out"
    done
    

    因为 DOT 不被视为变量名的一部分。

    【讨论】:

      【解决方案2】:

      我喜欢使用find,如果您的文件位于嵌套目录中,这很有用:

      find /user/test -name '*.txt' -exec fastqc "{}" -o "{}.out" \;
      

      find 将对它在 /user/test 中找到的所有 .txt 文件执行-exec 之后指定的命令(搜索是递归的)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-01
        • 1970-01-01
        相关资源
        最近更新 更多