本文介绍了Bash - 查找匹配的文件对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的文件夹中有很多文件:
I have many files in the folder:
Filename1.mp4
Filename2.mp4
Filename3.mp4
Etc.
以及在名称中添加后缀的许多文件:
As well as many files with added suffix to the name:
Filename1_x264.mp4
Filename2_x264.mp4
Filename3_x264.mp4
Etc.
我正在尝试使用 find
命令捕获匹配对并对其执行外部命令,但还没有找到方法.任何想法将不胜感激.
I am trying to catch the matching pairs using find
command and execute an external command on them but can't figure out a way to do it yet.Any ideas would be greatly appreciated.
推荐答案
使用 bash 及其参数扩展:
With bash and its Parameter Expansion:
for i in *_x264.mp4; do
j="${i%*_x264.mp4}.mp4" # remove suffix _x264.mp4 and add .mp4
if [[ -e "$j" ]]; then
echo "$i and $j exists"
fi
done
这篇关于Bash - 查找匹配的文件对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!