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