How to cut the last field from a shell string

user558134 picture user558134 · Dec 30, 2010 · Viewed 53.3k times · Source

How to cut the last field in this shell string

LINE="/string/to/cut.txt"

So that the string would look like this

LINE="/string/to/"

Thanks in advance!

Answer

Lucas Jones picture Lucas Jones · Apr 3, 2011

For what it's worth, a cut-based solution:

NEW_LINE="`echo "$LINE" | rev | cut -d/ -f2- | rev`/"