Hi,
Can someone let me know how to find the reverse of the basename i.e
i have /apps/tiv/pmon/xxxx.dat and I want /apps/tiv/pmon/
Thanks
Hi,
Can someone let me know how to find the reverse of the basename i.e
i have /apps/tiv/pmon/xxxx.dat and I want /apps/tiv/pmon/
Thanks
Check out dirname
try this:
cat test
/apps/tiv/pmon/xxxx.dat
sed 1,$"s/........$//g" test
/apps/tiv/pmon/
Ksh builtin
$var=/home/admin/test/123.sh
$echo $var
/home/admin/test/123.sh
$echo ${var%/*}
/home/admin/test
Alternative in python
>>> import os
>>> os.path.split("/apps/tiv/pmon/xxxx.dat")
('/apps/tiv/pmon', 'xxxx.dat')
>>> os.path.split("/apps/tiv/pmon/xxxx.dat")[0]
'/apps/tiv/pmon'
>>>
Excellent !! Thanks,
Small question,
In the statement, what does %/* infer to,
$echo ${var%/*}
I have come across
${var-nvar} if var unassigned return nvar, ${var+nvar}, if var assigned returned nvar. But could you tell me the signifcance of %/* pls ?,
Thanks
$echo ${var%/*}
Strips shortest match of "/*" from back of string var.