Advertisement
dzocesrce

[OS] Moving .csv files

Jan 21st, 2024 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.65 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# -ne 2 ]
  3. then
  4.     echo "USAGE: `basename $0` imenik_od imenik_do"
  5.     exit 1
  6. fi
  7. if [ ! -d $2 ]
  8. then
  9.     mkdir -p $2
  10. fi
  11. FROM=$1
  12. TO=$2
  13. files=`ls -l $FROM | grep ^- | grep [A-Z][A-Z]*\.csv$ | awk 'print $9'`
  14. for file in $files
  15. do
  16.     filename=`awk -F. {print $1}`
  17.     #first cut+paste the .csv files
  18.     mv ${FROM}${file} ${TO}${file}
  19.     #then rename(change) their extension
  20.     mv ${TO}${file} ${TO}${filename}.moved_csv
  21. done
  22. sum_filesizes=`ls -l $TO | grep ^- | awk '$9~/\.moved_csv$/ {print $5}' | awk 'BEGIN {total=0} {total+=$1} END {print total}'`
  23. echo "Vkupnata golemina na premestenite datoteki e $sum_filesizes"
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement