cut file extension

Owen Townend owen.townend at gmail.com
Wed Feb 20 14:21:30 UTC 2008


On 2/21/08, Heinrich Rebehn <rebehn at ant.uni-bremen.de> wrote:
>
> Owen Townend wrote:
> > On 2/20/08, David Restall - System Administrator <dave at restall.net>
> wrote:
> >> Hi,
> >>
> >>> On 2/20/08, Germain Morbe <germain.morbe at web.de> wrote:
> >>>> Hi all,
> >>>>
> >>>> im looking for a solution to strip the file extension
> >>>> within a bash script.
> >>>>
> >>>> thanks
> >>>>
> >>>> --
> >>>> ubuntu-users mailing list
> >>>> ubuntu-users at lists.ubuntu.com
> >>>> Modify settings or unsubscribe at:
> >>>> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
> >>>>
> >>> Hey,
> >>>   Look into `sed`. Something like this should do it
> >>>   `sed -e 's/.*$//'`
> >>>
> >>>   That's from the top of my head though, check it first!
> >> man basename may be useful :-)
> >>
> >> and the Owen's sed command isn't quite right, use 's/\..*$//'.
> >>
> >> The cut command could also be used using a delimter of . and so could
> >> awk.  TMTOWTDI :-)
> >>
> >> TTFN
> >
> >
> > ahah, that's closer to what I was aiming for, but it still doesn't
> > account for files like '
> > file.name.ext' cutting them to 'file' though  it should only match the
> end
> > of the line... ?
> >
> $ file=file.name.ext
> $ echo ${file%.*}
> file.name
>
> Is that what you want? :-)
>
> -Heinrich
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users



Seems to work, so yep.

I was thinking there must be a way to do this quickly in sed,
but I can't seem to find the right regex to match it correctly.
ah well, a solution in search of a problem now with it fixed.

cheers,
Owen.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20080221/601c5680/attachment.html>


More information about the ubuntu-users mailing list