I am reading one property file which contains some file paths using shell script. Now depending on this file path I want to create name of zip file. Something like this...My property file contents::
path=tmp/inputs/logs/abc
path=tmp/backup/inte/xyz
destpath=abc/xyz
Now I am able to create file name as abc.zip and xyz.zip as:
paths=`grep path myfile.property |cut -d= -f2`
d_path=`grep destpath myfile.property |cut -d= -f2`
filename=$d_path/$(basename $paths).zip
Which create abc.zip and xyz.zip. But I want to create name by taking last three parameter of the path. Something like this...
- for
abc.zip
it should beinputs_logs_abc.zip
and - for
xyz.zip
it should bebackup_inte_xyz.zip
EDIT
Paths=`grep path myfile.txt |cut -d= -f2`
d_Path=`grep destpath myfile.txt |cut -d= -f2`
for s_Path in $Paths
do
prefix=${Paths%%/*/*/*}
without_prefix=${Paths##${prefix}/}
slashes_to_underscores=${without_prefix//\//_}
zipFile=$d_Path/${slashes_to_underscores}.zip
find $s_Path -type f -name "*.log" | xargs zip -mT $zipFile -@
done
Above is my code.By using this i am not able to achieve my target. Can somebody help me in this?