Search code examples
linuxsvnbashcode-golf

Bash text parsing golf


I am writing a shell script to, among other things, determine the last time a branch was made in a subversion repository. The following code works:


        DEV='http://some/svn/server/'
        BRANCH='some/repos/branches/'
        LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r`
        LAST_UPDATE=${LAST_UPDATE:0:10}

But I am not liking the last two lines. How can I combine them together?

NOTE: 

`svn list http://some/svn/server | sort -r`
will return a list of folders such as:
2009-01-12/
2009-01-11/
...
2009-01-01/

I am just trying to remove the trailing slash


Solution

  • How about:

        LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r | awk -F\/ '{print $1}'`
    

    I've not tested it, and I'm not sure if the quotes inside the back-ticks will cause any problems, but otherwise I can't see why it wouldn't work...

    Ben