Search code examples
stringshellcut

How to cut the last field from a shell string


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!


Solution

  • I think you could use the "dirname" command. It takes in input a file path, removes the filename part and returns the path. For example:

    $ dirname "/string/to/cut.txt"
    /string/to