-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarData_2lvls.sh
executable file
·51 lines (39 loc) · 1.44 KB
/
tarData_2lvls.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
47
48
49
50
51
#!/bin/bash
## dir_lev1_a
## dir_lev2_a
## dir_lev2_b
## dir_lev1_b
## dir_lev2_a
## dir_lev2_c
##
## tar one level of subfolders in each folder as a separate tar ball
## tar files are labeled by the top level and bottom level folder names
##...... vars to modify ...............
baseDir='/projects/crunchie/bnst' # up to path that you don't want in the tar ball when it unpacks
sourceTar='DATA_MRI/DATA_bnst2018'
targetTar='data_orig/data_orig_bnst2018'
cd $baseDir
pwd
[[ -d $targetTar ]] || mkdir $targetTar
#declare -a subList=('sub047' 'sub048' 'sub049' 'sub050' 'sub051');
## in this example, each folder has the format sub%03d, so we can specify a range of numbers of the
## matching folders we want to go through
start=34;#31;#27;
end=40;#33;#30;
# for i in {0..2} {4..6} {7..11..2}; do echo $i; done
for i in $(seq $start $end)
#for ss in "${subList[@]}" # if you have specified a list of subfolders to go thru specifically
#for ss in `ls ${sourceTar}/indiv | grep sub` # if you want to go through all subfolders
do
ss=$(printf "sub%02d" "$i")
subSrc="${sourceTar}/${ss}"
echo ............. tarring subj $ss ............
echo subsrc=$subSrc
for ww in `ls ${subSrc}`
do
subfolder=${subSrc}/${ww}
ff="${ss}.${ww}.tar.gz"
echo Checking archive $ff -- if does not exist then creating
[[ -f ${targetTar}/${ff} ]] || tar cvfz $targetTar/$ff ${subfolder} > ${targetTar}/${ss}.${ww}.log
done
done