我有 1000 多个文件夹,每个文件夹包含一个 .wav 文件和一个 .txt 文件(文件夹示例)。文本文件包含时间间隔,我需要根据每个文本文件给出的时间间隔将 .wav 文件修剪成剪辑(请注意,文本文件位于不同的文件夹中)。我从这里输入链接描述中得到了以下脚本
#!/bin/bash
index=0
while read this; do
if [ $index -gt 0 ]; then
sox sound.wav clip-$index.wav trim $start $this-$start
fi
((index+=1))
start=$this
done < times.txt
但是,它是针对单个文件的,并且只能用于当前目录中的文件。如何使其适用于子文件夹并进入循环?
基本上,您希望对所有子目录执行此循环。这意味着您需要遍历子目录:
#!/bin/bash
topdir=$(pwd)
find . -type d | while read dir ; do
cd "$dir"
if [ -f sound.wav -a -f times.txt ] ; then
index=0
while read this; do
if [ $index -gt 0 ]; then
sox sound.wav "clip-$index.wav" trim "$start" "$this-$start"
fi
((index+=1))
start="$this"
done < times.txt
fi
done
我假设你问题中的循环做了你想要它做的事情,我只是添加了一些引号。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句