Honored Contributor Honored Contributor
Re: change character , when a string occurs ( possible one liner )

Hey;

 

The previous post got it, but just for completeness:

 

Var="Abc/Def/Ghi"

echo ${Var#*/}   = Def/Ghi

echo ${Var##*/} = Ghi

 

One hash is the shortest possible match from the beginning of the string; Two hashes is the biggest possible match.

 

A similar thing can be done from the other side of the string:

 

echo ${Var%/*}     = Abc/Def

echo ${Var%%/*} = Abc

 

You need 2 hashes in your case because one hash would only match the first '/':

 

Vg=/dev/vg01

echo ${Vg#*/} = dev/vg01

echo ${Vg##*/} = vg01

 

Those are really useful constructs; I use them in my scripts quite a bit.

 

Hope that helps.

 

Doug O'Leary


------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html