Loop over multiple file extensions from bash script

后端 未结 2 894
梦如初夏
梦如初夏 2020-12-07 04:18

I need a bash script for use in the Linux terminal which should go something like:

#!/bin/bash 

for textgrid_file in ./*.TextGrid and for wav_file in ./*.w         


        
相关标签:
2条回答
  • 2020-12-07 04:36

    You can use an array support to iterate over first glob pattern and use 2nd file from array:

    waves=(*.wav)
    
    k=0
    for textgrid_file in *.TextGrid; do
        praat --run pitch.praat "$textgrid_file" "${waves[k++]}" >> output.txt
    done
    
    0 讨论(0)
  • 2020-12-07 05:00

    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.

    0 讨论(0)
提交回复
热议问题