Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 02 Jul 2010 19:35:01 +0400
From:      Anonymous <swell.k@gmail.com>
To:        Aiza <aiza21@comclark.com>
Cc:        "questions@freebsd.org" <questions@freebsd.org>
Subject:   Re: Bourne .sh ?
Message-ID:  <86ocepx5ga.fsf@gmail.com>
In-Reply-To: <4C2D2839.3040909@comclark.com> (Aiza's message of "Fri, 02 Jul 2010 07:43:53 %2B0800")
References:  <4C2D2839.3040909@comclark.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Aiza <aiza21@comclark.com> writes:

> I have a file containing this
>
> drwxrwxr-x  14 89987  546  512 Jun  6  2009 7.2-RELEASE
> drwxrwxr-x  14 89987  546  512 Mar 23 04:59 7.3-RELEASE
> drwxrwxr-x  13 89987  546  512 Nov 23  2009 8.0-RELEASE
> drwxrwxr-x  13 89987  546  512 Jul  1 04:56 8.1-RC2
>
> I want to strip off everything to the left of the release
> version so I end up with this.
>
> 7.2-RELEASE
> 7.3-RELEASE
> 8.0-RELEASE
> 8.1-RC2
>
> How would I code to do this?

Use...

- glob expansion + echo builtin, e.g.

    $ cd /path/to/blah && echo *
or
    $ cd /path/to/blah && for f in *; do echo $f; done

- field splitting, e.g.

    $ ls -l | while read $(while [ $((i+=1)) -le 9 ]; do echo p$i; done); do echo $p9; done

- stat(1) if you need not only filename but e.g. date

Of course you can use smth like cut/sed/awk/whatever but they'll only
make your script slower if you use them often.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86ocepx5ga.fsf>