linux - Extract string between two / from right -
extract string between 2 / right
command preparation:
input:- [directories name not constant]
example 1:-
/dir1/dir2/ example 2:-
/dir1/dir2/dir3/dir4/ i want output below
example 1 output:-
nohup dsmc arch /dir1/dir2/ -subdir=yes > /tsm/backuplogs/dir2_`date +%d%m%y_%h_%m`.log & example 2 output:-
nohup dsmc arch /dir1/dir2/dir3/dir4/ -subdir=yes > /tsm/backuplogs/dir4_`date +%d%m%y_%h_%m`.log &
use basename program extract last dir paths, this:
path=/dir1/dir2/dir3/dir4/ echo "nohup dsmc arch $path -subdir=yes > /tsm/backuplogs/$(basename $path)_\`date +%d%m%y_%h_%m\`.log &" the above line output:
nohup dsmc arch /dir1/dir2/dir3/dir4/ -subdir=yes > /tsm/backuplogs/dir4_`date +%d%m%y_%h_%m`.log &
Comments
Post a Comment