Advertisement
dzocesrce

[OS] Moving files all day long...

Jan 22nd, 2024
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.16 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# -ne 3 ]
  3. then
  4.     echo "USAGE: `basename $0` src dst some_file.txt"
  5.     exit 1
  6. fi
  7. if [ ! -d $1 ]
  8. then
  9.     echo "Imenikot prosleden kako argument ne postoi"
  10.     exit 1
  11. fi
  12. if [ -d $2 ]
  13. then
  14.     rm $2
  15. fi
  16. mkdir $2
  17. if [ -f $3 ]
  18. then
  19.     rm $3
  20. fi
  21. touch $3
  22. #get all files from source folder
  23. FILES=`ls -R $1 | grep ^- | awk 'print $10'`
  24. for file in $FILES
  25. do
  26.     #change their name
  27.     file_name=`echo $file | sed -e "s/\..*$//" -e "s/\'/'/_/"`
  28.     file_extension=`echo $file | awk -F. 'print $NF'`
  29.     sodrzina_file=`cat $file`
  30.     #get sodrzina from the file we wanna move
  31.     FILES2=`ls -R $2 | grep ^- | awk 'print $10'`
  32.     #get all the moved files
  33.     for file2 in $FILES2
  34.     do
  35.         sodrzina_file2=`cat $file2`
  36.         #check if the file we are about to move happens to have same sodrzina with some of the moved
  37.         if [ "$sodrzina_file" == "$sodrzina_file2" ]
  38.         then
  39.             echo "Fajlovite ${1}${file} i ${2}${file2} imaat ista sodrzina" >> $3
  40.         fi
  41.     done
  42.     #move and rename
  43.     mv ${1}${file} ${2}${file}
  44.     mv ${2}${file} ${2}${file_name}.${file_extension}
  45. done
  46. #output
  47. cat $3    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement