Date: Wed, 16 Jun 2010 12:40:03 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: Aiza <aiza21@comclark.com> Cc: "questions@freebsd.org" <questions@freebsd.org> Subject: Re: .sh and sed Message-ID: <4C18B813.7020608@infracaninophile.co.uk> In-Reply-To: <4C18B276.4080900@comclark.com> References: <4C18B276.4080900@comclark.com>
next in thread | previous in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 16/06/2010 12:16:06, Aiza wrote:
> Trying to use sed to remove the path from the file name.
> Variable has complete path plus the file name
> /usr/local/etc/filename
> Need variable containing only the file name.
> Is the sed utility the best thing to use?
> Is there some other utility better suited for this task.
> How would sed by coded to do this?
sh(1) can do this alone, without recourse to any external programs.
path='/usr/local/etc/filename'
fname=${path##*/}
echo $fname
There is also an external program basename(1)
The same trick with sed(1):
fname=$( echo $path | sed -e 's,^.*/,,' )
but the built-in prefix matching stuff is preferable since it is more
efficient.
Cheers,
Matthew
- --
Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard
Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matthew@infracaninophile.co.uk Kent, CT11 9PW
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkwYuBMACgkQ8Mjk52CukIxF2QCcDqIpSGa98Wrp6dD+ii1FGJ5q
p4oAn2NJxqIksx9iS0QSzT8Ypme6wwE4
=aFrN
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C18B813.7020608>
