LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   help with cut command (https://www.linuxquestions.org/questions/programming-9/help-with-cut-command-926496/)

sunilsagar 01-30-2012 08:29 AM

help with cut command
 
Hello All,

I need help to change the path using cut. I tried lot of things, bit no luck.

Path = /a/b/c/d/e/f/g/
Output = /a/b/c/d/e/f

I want output as shown above. Please help

Thanks.

corp769 01-30-2012 08:38 AM

Besides wanting to cut part of it off, are you looking to strip the last directory, and that's it? If so, you can simply use sed for this:
Code:

echo "/a/b/c/d/e/f/g/" | sed 's/.\{3\}$//'
Note that you need to use, change, modify, etc, to your liking's.

Cheers,

Josh

unSpawn 01-30-2012 08:42 AM

'man cut': the "-d" and "-f" args or even simpler: VAR="/a/r/g/s"; dirname $VAR

David the H. 01-31-2012 09:15 AM

If the path is stored in a shell variable,then simple parameter substitution is all you need:

Code:

$ path='/a/b/c/d/e/f/g/'
$ echo "${path%/*/}"
/a/b/c/d/e/f

More shell string manipulations.

Cedrik 01-31-2012 09:44 AM

(deleted)
' dirname ' was already refered by unSpawn :/

sunilsagar 02-01-2012 05:04 AM

thanks so much , there are so may ways .. din't knew that. all worked.


All times are GMT -5. The time now is 12:34 PM.