简体   繁体   English

选择并遍历两个目录linux中的差异

[英]Select and looping over differences in two directories linux

I have bash script that that loops through files in the raw folder and puts them into the audio folder. 我有bash脚本,该脚本循环遍历原始文件夹中的文件,并将它们放入音频文件夹中。 This works just fine. 这样很好。

#!/bin/bash
PATH_IN=('/nas/data/customers/test2/raw/')
PATH_OUT=('/nas/data/customers/test2/audio/')

mkdir -p /nas/data/customers/test2/audio
IFS=$'\n'
find $PATH_IN -type f -name '*.wav' -exec basename {} \; | while read -r file; do
    sox -S ${PATH_IN}${file} -e signed-integer ${PATH_OUT}${file}
done

My issue is that, as the folders grow I do not want to run the script on the files that has already been converted, so I would like to loop over only the files that has not been converted yet. 我的问题是,随着文件夹的增加,我不想在已经转换的文件上运行脚本,因此我只想循环浏览尚未转换的文件。 Ie the files only in raw but not in audio. 即,仅原始文件,而不是音频文件。

I found the function 我找到了功能

diff audio raw 差异音频原始

That can I do just that, but I cannot find a good way to incorporate this into my bash script. 我可以做到这一点,但是我找不到将其合并到我的bash脚本中的好方法。 Any help or nudges in the right direction would be highly appreciated. 朝正确方向的任何帮助或推动将不胜感激。

You could do: 您可以这样做:

diff <(ls -1a $PATH_OUT) <(ls -1a $PATH_IN) | grep -E ">" | sed -E 's/> //'

The first part will diff the files on both folders, the second part will filter out to get only the additions, and the third one will clean the list from the diff symbols to get just the names. 第一部分将对两个文件夹中的文件进行比较,第二部分将进行过滤以仅获取添加内容,第三部分将从diff符号中清除列表以仅获取名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM