Advertisement
Guest User

Untitled

a guest
May 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement