2

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 ./*.wav
do 
   praat --run pitch.praat "$textgrid_file" "$wav_file" >> output.txt
done

I.e. 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. How can I implement it via bash scripting?

2

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.