Question

I have mfcc features in one file and f0 in another I want to put them together in one file for all the files in the directory and save it to a file in another directory for each file in mfc

paste -d '\t' /home/Documents/mfc/3.mfc.txt /home/Documents/f0/34-114.f0.txt > /home/fs/34-114.txt

the command works for one file I want to make it work for all files

I tried

for file in /home/Documents/mfc/*; do

    paste -d '\t' $file /home/Documents/f0/$(basename $file ).f0.txt > /home/Documents/fs/$(basename $file ).txt

done

which returned error saying files not found as the extensions of files in the f0 folder were different

paste: /home/home/Documents/f0/6.raw.f.mfc.txt.f0.txt: No such file or directory
paste: /home/home/Documents/f0/7.raw.f.mfc.txt.f0.txt: No such file or directory
paste: /home/home/Documents/f0/8.raw.f.mfc.txt.f0.txt: No such file or directory
paste: /home/home/Documents/f0/9.raw.f.mfc.txt.f0.txt: No such file or directory
paste: /home/home/Documents/f0/10.raw.f.mfc.txt.f0.txt: No such file or directory
Was it helpful?

Solution 2

This script actually did the trick. It was the file name and extensions that actually messed up the script I posted in the question.

for file in /home/Documents/mfc//*; do

fname=$(basename "$file" .raw.f.mfc.txt)

    paste -d '\t' $file /home/Documents/f0/$fname.f0.txt > /home/Documents/fs/$fname.txt

done

OTHER TIPS

I am not sure if this is what you want, but you can try this:

#!/bin/bash
arr=(/home/Documents/mfc/*txt)
arr2=(/home/Documents/f0/*.txt)
for i in $(seq 0 $((${#arr[@]}-1))); do
    paste -d "\t" ${arr[$i]} ${arr2[$i]}
done

This script assumes that you have same number of files in both folders. If you want output to be put in multiple files you need to redirect standard output to some file

E.g.

    paste -d "\t" ${arr[$i]} ${arr2[$i]} >> file$i.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top