Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.87 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. rename()
  4. {
  5. local old_path=$1 char=$2
  6. echo "$old_path" | sed 's/^\([^.]*\)/\1'$char'/'
  7. }
  8.  
  9. find_name()
  10. {
  11. local catalog_name=$1 filename=$2
  12. found=0
  13. files=`ls "$catalog_name"`
  14. for file in files
  15. do
  16. if [ $file = $filename ]
  17. then
  18. found=1
  19. fi
  20. done
  21. echo "$found"
  22. }
  23.  
  24. catalog_name=$1
  25. archive_name=$2
  26.  
  27. if [ ! -d $catalog_name ]
  28. then
  29.  
  30. mkdir $catalog_name
  31.  
  32. fi
  33.  
  34. count=0
  35.  
  36. for extension in $@
  37. do
  38.  
  39. count=$(( $count + 1 ))
  40.  
  41. if [ $count -ge 3 ]
  42. then
  43.  
  44. paths=`find ~/techprog -name "*.$extension"`
  45.  
  46. for path in $paths
  47. do
  48.  
  49. temp="$path"
  50. src_filename=`basename "$path"`
  51.  
  52. while [ `find_name "$catalog_name" "$src_filename"` -gt 0 ]
  53. do
  54. new_path=`rename "$path" "_"`
  55. mv "$path" "$new_path"
  56. path="$new_path"
  57. src_filename=`basename "$path"`
  58. done
  59.  
  60. cp "$path" "$catalog_name"
  61.    
  62. done
  63.  
  64. fi
  65.  
  66. done
  67. tar -czf $archive_name "$catalog_name"
  68. echo "done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement