command to strip suffix in .sh script
Polytropon
freebsd at edvax.de
Wed Jun 2 10:10:15 UTC 2010
On Wed, 02 Jun 2010 16:15:22 +0800, Aiza <aiza21 at 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, ...
More information about the freebsd-questions
mailing list