#!/bin/bash
source_dir_a=$1 // Directory containing a files given as first argument
source_dir_b=$2 // Directory containing b files given as second argument
a_files=$(ls $source_dir_a) // Save list of files in provided a dir
for a_file in $a_files; do // Loop over the files in the a dir
echo "a_file=$a_file"
folder=$(echo $a_file | sed -e 's/^a//g') // Remove the leading "a" of a files using a regex for the storing folder name
echo "folder=$folder"
b_file=$(echo b$folder) // Adding leading "b" to folder name to have b_file name
echo "b_file=$b_file"
mkdir $folder // Create output folder
mv $source_dir_a/$a_file $source_dir_b/$b_file $folder // Move the a and b files in output folder
done
1条答案
按热度按时间gojuced71#
您可以使用基本的bash脚本轻松地完成此操作,下面是一个如何完成此操作的示例,并附有解释步骤的注解。
缺少的是一些错误检查,特别是当一些预期的文件不存在时。