What I want to do is to create a script that will interpret the following string and save into variables part of its name
m02_+1+7_London_0000$01.cfg as
------X-Y–City---------
X=1
Y=7
City=London
after that I want the script to
mkdir City (this should create a folder called London)
mkdir City/M’X.Y’ (this should create a subfolder called London/M1.7
then I want to copy the files that go all the files with the same City and X and Y to the same subfolder
City/MX.Y
I will need some help start doing that. And I think the first would be to get part of the filenames strings into variables.
I would like to thank you in advance for your help
#!/bin/bash
#
# Set base for source dir
SOURCEDIR="."
# Set base for destination dir
BASEDIR="."
FILES=$SOURCEDIR/m02_*.cfg
for FILE in $FILES ; do
F=$(basename $FILE)
echo $F
X=$(echo $F | cut -d '+' -f 2)
Y=$(echo $F | cut -d '+' -f 3 | sed -e "s/_.*//")
CITY=$(echo $F | cut -d '_' -f 3)
if ! test -d $BASEDIR/$CITY/M$X.$Y ; then
mkdir -p $BASEDIR/$CITY/M$X.$Y
fi
cp -a $FILE $BASEDIR/$CITY/M$X.$Y/
done
exit 0
I see that you get plenty of help here in spite of the fact that you did not ask rthis in the subforum with the name Programming/Scripting under Developement.
Next time please consider asking your scripting questions there.
On 2011-07-13 15:36, hcvv wrote:
>
> Dear alaios,
>
> I see that you get plenty of help here in spite of the fact that you
> did not ask rthis in the subforum with the name Programming/Scripting
> under Developement.
> Next time please consider asking your scripting questions there.
IMHO, it should be moved, lest it gets long.
–
Cheers / Saludos,
Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)