Im trying to extract a directory from a path entered by the user
Lets say the path is
path=/home/bliss/files/myfile.txt
i wanna extract "/home/bliss/files" from $path ... how can i do this?
Im trying to extract a directory from a path entered by the user
Lets say the path is
path=/home/bliss/files/myfile.txt
i wanna extract "/home/bliss/files" from $path ... how can i do this?
echo "/home/bliss/files/myfile.txt" | awk -F"/" '{print $4}'
Thanks for the reply dinjo ...
but what if the path is read from the terminal... ie, $path can be anything - like, /home/myfile.txt
/home/bliss/myfile.txt
/home/one/two/myfile.txt
/home/one/two/three/myfile.txt or something else ?
dirname "/home/one/two/three/myfile.txt"
echo "/home/one/two/three/myfile.txt" | sed 's|\(.*\)/.*|\1|'
Thanks Panyam ... thats much more flexible !