-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapproximateTimeDirectory.sh
47 lines (37 loc) · 1.17 KB
/
approximateTimeDirectory.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# ----------------------------------------------------------------------- #
# approximateTimeDirectory.sh
#
# Approximate time directories to nearest decimal. Starting, ending and
# intervals should be given.
#
# Example call:
# approximateTimeDirectory 14400 14401.8 0.2
# where 14400.000000011 and 14401.800000012 exist.
#
# Regis Thedin
# May 8, 2022
# ----------------------------------------------------------------------- #
approximateTimeDirectory(){
GREEN='\033[0;32m'
NC='\033[0m'
ff=$1
lf=$2
dt=$3
echo -e "${GREEN} Approximating to the nearest" $dt "value${NC}"
# Get last and first directory or file in directory.
firstFile_=$(ls -dvr $ff*|tail -1)
lastFile_=$(ls -dv $lf*| tail -1)
# Remove trailing slashes from dir name
firstFile=$(echo $firstFile_ | sed 's:/*$::')
lastFile=$(echo $lastFile_ | sed 's:/*$::')
echo " First file:" $firstFile
echo " Last file:" $lastFile
for f in $(seq $ff $dt $lf); do
#new=$(printf "$f "$f*")
echo "$f*" "to be moved into" "$f"
mv -i -- $f* $f
done
echo -e "${GREEN} Done. ${NC}"
}