Date: Wed, 2 Jun 2010 12:10:12 +0200 From: Polytropon <freebsd@edvax.de> To: Aiza <aiza21@comclark.com> Cc: "questions@freebsd.org" <questions@freebsd.org> Subject: Re: command to strip suffix in .sh script Message-ID: <20100602121012.38e91934.freebsd@edvax.de> In-Reply-To: <4C06131A.6010107@comclark.com> References: <4C06131A.6010107@comclark.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 02 Jun 2010 16:15:22 +0800, Aiza <aiza21@comclark.com> wrote:
> I have this code
>
> archive_name=`echo -n "${fromarchive}" | tr -c '[:alnum:]' _`
>
> ` is the key under Esc key and ' key is next to enter key.
>
> fromarchive value is archivename-201006021514.34.tar.gz
>
> I want to strip the suffix -201006021514.34.tar.gz from the archivename.
>
> The archivename can be upper and lower case letters interspersed with _
>
>
> Do I have syntax problem with the code? I get no error on it.
>
> Do I have the tr command coded correctly?
>
> Or should I be using something else instead of tr command?
Maybe "cut" can help:
% echo 'archivename-201006021514.34.tar.gz' | cut -d '-' -f 1
archivename
Cutting -f 2 will give you the remaining component.
% echo 'archivename-201006021514.34.tar.gz' | cut -d '-' -f 2
201006021514.34.tar.gz
To cut off the suffix (.tar.gz), consider using "basename".
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100602121012.38e91934.freebsd>
