Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # @Author: Farmer Li
- # @Date: 2019-05-14 14:32:34
- # @Last Modified by: Farmer Li
- # @Last Modified time: 2019-05-14 15:47:08
- usage() {
- echo "Usage: ${0} source_dir target_dir"
- }
- recursively_processing() {
- # Strip the last separator of the path
- source_dir=${1%/}
- target_dir=${2%/}
- pattern=$3
- for source_file in $( find $source_dir -name $pattern); do
- echo "Processing file: ${source_file}"
- src_dir_full=`dirname $source_file`
- dst_dir_full=${src_dir_full/$source_dir/$target_dir}
- if [[ ! -d $dst_dir_full ]]; then
- mkdir -p $dst_dir_full
- fi
- target_file="${dst_dir_full}/`basename $source_file`"
- # Run custom command here
- echo "Output to: ${target_file}"
- done
- }
- if [[ $# -eq 2 ]]; then
- recursively_processing $1 $2 "*.txt"
- else
- usage
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement