SHARE
TWEET

Untitled

a guest May 24th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # @Author: Farmer Li
  3. # @Date:   2019-05-14 14:32:34
  4. # @Last Modified by:   Farmer Li
  5. # @Last Modified time: 2019-05-14 15:47:08
  6.  
  7. usage() {
  8.     echo "Usage: ${0} source_dir target_dir"
  9. }
  10.  
  11. recursively_processing() {
  12.     # Strip the last separator of the path
  13.     source_dir=${1%/}
  14.     target_dir=${2%/}
  15.     pattern=$3
  16.     for source_file in $( find $source_dir -name $pattern); do
  17.         echo "Processing file: ${source_file}"
  18.         src_dir_full=`dirname $source_file`
  19.         dst_dir_full=${src_dir_full/$source_dir/$target_dir}
  20.         if [[ ! -d $dst_dir_full ]]; then
  21.             mkdir -p $dst_dir_full
  22.         fi
  23.         target_file="${dst_dir_full}/`basename $source_file`"
  24.  
  25.         # Run custom command here
  26.         echo "Output to: ${target_file}"
  27.     done
  28. }
  29.  
  30. if [[ $# -eq 2 ]]; then
  31.     recursively_processing $1 $2 "*.txt"
  32. else
  33.     usage
  34.     exit 1
  35. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top