-2

I have a directory called "bin", where i have a script called "GetMaxFreqs"

To execute it i need to do:

./GetMaxFreqs -w file.freqs file.wav

Inside the "bin" folder i have a folder called "dataset" where i have 100 ".freqs" and 100 ".wav" files, and i want to run the script to do the "GetMaxFreqs" automatically.

i tried:

for f in database/*.wav; do ./GetMaxFreqs -w "$f".freqs *.wav; done

and:

for f in database/*.wav; do ./GetMaxFreqs -w "$f".freqs "$f".wav; done

But in the first one the output is the same for every fille, and in the second it gives an error.

Godogo
  • 27
  • 8
  • In the second example command, shouldn't `"$f".wav` be `"$f"`? BEWARE: first backup that entire tree where `database` resides. –  Jan 15 '21 at 19:13
  • but in the second command i need to choose .wav files otherwise the program doesn't work – Godogo Jan 15 '21 at 19:18

2 Answers2

2

I think you want basename

Assuming you want to invoke ./GetMaxFreq -w somefile.freqs somefile.wav, and assuming there aren't any spaces any of the filenames, then try this:

for w in database/*.wav; do
  f=${basename $w}.freqs
  ./GetMaxFreqs -w $f $w
done

Try this if you have spaces:

for w in database/*.wav; do
  f="${basename $w}.freqs"
  ./GetMaxFreqs -w "$f" "$w"
done
paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • there are spaces on the file names and also some characters, its names of songs so its on the format like: "50 cent - in da club" – Godogo Jan 15 '21 at 19:16
  • I've updated my reply. Again: the key point is you need "basename". Please post back if it works for you. – paulsm4 Jan 15 '21 at 19:29
  • it has this error "bash: ${basename $w}.freqs: bad substitution" I dont know if it has to do with your code, but i need to get the .freqs and the .wav that are on the database folder, so when you do this part: "./GetMaxFreqs -w "$f" "$w"" shouldn't it be like: "./GetMaxFreqs -w database/"$f" database/"$w" " ?? – Godogo Jan 16 '21 at 14:33
1

This is similar to the paulsm4's solution...it worked for me (assuming that you want both of the file names to be the same, like file1.freqs and file1.wav):

for w in database/*.wav; do
    f=`basename -s .wav $w`.freqs;
    ./GetMaxFreqs -w database/$f $w;
done;

hope I got what you meant.

after running the script

BlueDiary9
  • 95
  • 2
  • 6
  • it seems correct, but somehow it doesnt work, it says that the audio file is incorrect which means that the "$w" part is incorrect, are u also taking the "$w" files from the folder database? – Godogo Jan 16 '21 at 14:35
  • I checked again... by running the ./GetMaxFreqs inside the bin directory, and all other files in the child directory named database. It worked again. I even run the following script inside the bin directory: echo "Hello" > $w and it was successful. – BlueDiary9 Jan 16 '21 at 16:16