[英]Loop over multiple file extensions from bash script
I need a bash script for use in the Linux terminal which should go something like: 我需要在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
Ie I need to iterate through pairs of files with extensions .textgrid
and .wav
because in my Praat script pitch.praat
I have two arguments to pass. 即我需要遍历具有扩展名
.textgrid
和.wav
的文件对,因为在我的Praat脚本pitch.praat
我有两个参数要传递。 How can I implement it via bash scripting? 如何通过bash脚本实现它?
You can use an array support to iterate over first glob pattern and use 2nd file from array: 您可以使用数组支持来遍历第一个glob模式,并使用数组中的第二个文件:
waves=(*.wav)
k=0
for textgrid_file in *.TextGrid; do
praat --run pitch.praat "$textgrid_file" "${waves[k++]}" >> output.txt
done
If I understand you right, both filename share the same basename. 如果我理解正确,两个文件名共享相同的基本名。
#!/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
Extract the common basename with basename. 用basename提取通用basename。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.