HI,
i have data in one variable like
out=/usr/sbin/filename and i want output like only
out=filename
how to do
HI,
i have data in one variable like
out=/usr/sbin/filename and i want output like only
out=filename
how to do
out=$(which filename)
out=$(basename $out)
hth
see i'm having
proc=/usr/sbin/syslogd
and i want only syslogd to store in other variable say proc1
What is the full line to parse?
Only syslogd shall be returned.
EDIT:
Wether you first fill "out" with:
out=$(which syslogd)
or
out=/usr/sbin/syslogd
to then get:syslogd out of $out
its both ways:
out=$(basename $out)
Sorry for the irritation on that.
Hi,
Could you please try the following code.
$ proc1=`echo $proc | sed 's/\// /3' | awk '{print$2}'`
Value of proc1 will be then as follows per your requirement.
$ echo $proc1
syslogd
Adding here one more approach for same too.
$ proc1=`basename $proc`
Output will be as follows then.
$ echo $proc1
syslogd
Thanks,
R. Singh
Just like in: How to get process name from PID?
But the value is already in the variable, and doesnt need to parsed by you.