-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfnadd
More file actions
executable file
·36 lines (33 loc) · 853 Bytes
/
fnadd
File metadata and controls
executable file
·36 lines (33 loc) · 853 Bytes
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
#!/bin/bash
if [ "$#" = "0" ]; then
echo Usage is not like that
exit
fi
for oldfile in $* ; do
# skip first arg b/c it's the number to add
if [ $oldfile != $1 ]; then
num=`echo $oldfile | sed s/[0-9]*-// | sed s/-.*//`
# sadly, strip leading 0's
strnum=`echo $num | sed s/^0*//`
newnum=$[ $strnum + $1 ]
# now try to put leading zero's back in
if let $[ $newnum < 10 ]; then
unstrnewnum="0000$newnum"
elif let $[ $newnum < 100 ]; then
unstrnewnum="000$newnum"
elif let $[ $newnum < 1000 ]; then
unstrnewnum="00$newnum"
elif let $[ $newnum < 10000 ]; then
unstrnewnum="0$newnum"
else
unstrnewnum=$newnum
fi
newfile=`echo $oldfile | sed s/-$num-/-$unstrnewnum-/`
echo $oldfile $newfile
mv $oldfile $newfile.tmp
fi
done
for file in *.tmp ; do
mv $file `echo $file | sed s/.tmp$//`
done
#xmv tmp