【问题标题】:Loop over multiple file extensions from bash script从 bash 脚本循环多个文件扩展名
【发布时间】:2018-03-05 05:24:51
【问题描述】:

我需要一个在 Linux 终端中使用的 bash 脚本,它应该类似于:

#!/bin/bash 

for textgrid_file in ./*.TextGrid and for wav_file in ./*.wav
do 
   praat --run pitch.praat "$textgrid_file" "$wav_file" >> output.txt
done

即我需要遍历扩展名为.textgrid.wav 的文件对,因为在我的Praat 脚本pitch.praat 中有两个参数要传递。如何通过 bash 脚本实现它?

【问题讨论】:

标签: bash


【解决方案1】:

您可以使用数组支持来迭代第一个 glob 模式并使用数组中的第二个文件:

waves=(*.wav)

k=0
for textgrid_file in *.TextGrid; do
    praat --run pitch.praat "$textgrid_file" "${waves[k++]}" >> output.txt
done

【讨论】:

    【解决方案2】:

    如果我没听错的话,两个文件名共享相同的基本名称。

    #!/bin/bash 
    for textgrid_file in ./*.TextGrid 
    do 
        name=$(basename $textgrid_file .TextGrid)
        wfile="$name.wav"
        praat --run pitch.praat "$textgrid_file" "$wfile" >> output.txt
    done
    

    用 basename 提取公共 basename。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-13
      • 2021-06-17
      • 2013-03-27
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多