Hi,
I have a variable , lets say
a=/disk1/net/first.ksh
i need to grep "first.ksh"
everytime "a" gets changed dynamically and i do not know how many '"/" are there in my variable.
Can somebody help me out.
Hi,
I have a variable , lets say
a=/disk1/net/first.ksh
i need to grep "first.ksh"
everytime "a" gets changed dynamically and i do not know how many '"/" are there in my variable.
Can somebody help me out.
in awk
echo $a| awk -F/ '{print $NF}'
great it works....
Can you please explain me the command
Or simply use basename -- or if your shell understands ${a##*/} then by all means use that.
The awk command splits its input into the character specified by the -F option (in this case "/"). So awk sees something like:
disk1 net first.ksh
Awk has an internal variable named "NF" which stands for the Number of Fields on the current line. In this case that's 3. So it's like writing:
awk '{ print $3 '}
which would print the third field of the input. Of course, it's not really 3 every time, just this time. So the last part of the path gets printed.
Thanks a lot....
is that i can take
/disk/net in one variable and first.ksh in one variable ?
basename $a
can you gimme an example please ?
Try...
a=/disk1/net/first.ksh
b=$(basename $a)
c=$(dirname $a)
Thanks man