Mailinglist Archive: opensuse (686 mails)

< Previous Next >
Re: [opensuse] bash: how to get file extension
  • From: "Carlos E. R." <robin.listas@xxxxxxxxxxxxxx>
  • Date: Fri, 19 Jul 2013 23:13:23 +0200 (CEST)
  • Message-id: <alpine.LNX.2.00.1307192246380.2653@Telcontar.valinor>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



On Monday, 2013-07-15 at 12:00 -0400, Brian K. White wrote:
On 7/15/2013 5:01 AM, lynn wrote:

ext=$(echo "$video_title" | sed 's/^.*\.//')

The problem is the .'s

I want to ignore all .'s until the final one (not just for this string).


You are saying you want the final answer to _include_ the dot? That is an unreasonably complicated thing to try to do for not enough gain. It's possible with sed, but you're working too hard to figure out that sed/regex syntax, and by forking a process to run sed, also making the computer work too hard.

The simple and practical answer is just to add the dot back in yourself like this:


One reason for wanting the dot is that you can reconstruct the entire string by concatenation: "path + name + extension". If the extension is missing, doing "name + dot + extension" would not get the original string.

Msdos libraries typically included routines to do all that. Linux aparently not, because extensions have (almost) no meaning. Sometimes I create my own path manipulation binary (in pascal).

- -- Cheers,
Carlos E. R.
(from 12.3 x86_64 "Dartmouth" at Telcontar)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iEYEARECAAYFAlHpq/MACgkQtTMYHG2NR9X2bgCfWmYtq8i3mo23JHNzCPwkWEvW
ur0AniI0Db3Xy85l6Hysq4Nm9u4Q1ItP
=9O/A
-----END PGP SIGNATURE-----
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >
References