Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Jul 2004 12:23:13 -0700
From:      Henrik W Lund <henrik.w.lund@broadpark.no>
To:        Kathy Quinlan <kat-free@kaqelectronics.dyndns.org>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: string manipulation in a shell script
Message-ID:  <40F97CA1.90500@broadpark.no>
In-Reply-To: <40F8E457.1030303@kaqelectronics.dyndns.org>
References:  <40F8E457.1030303@kaqelectronics.dyndns.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Kathy Quinlan wrote:

> Hi guys and Gals,
>
> I have a simple script:
>
> #!/bin/sh
>
> a=ia$(date +%d%m%Y)
>
> tar -cf "$a.zip" "/usr/home/projects/lunaria/items all"
> mv $a.zip /usr/home/itemsall/
>
> this nearly does what I want, I would like to put the time in the file 
> name aswell. If I put the %T in the date variable, the resultant value 
> for $a has : seperating the hours, minutes and seconds.
>
> Try as I might, I can not find away to remove the : and tar spits the 
> dummy at them and it causes an IO device error.
>
> I looked through sed and awk, and spent an hour playing, but all to no 
> avail.
>
> Anyhelp apreciated,
>
> Regards,
>
> Kat.

Greetings!

Did you try this:

b=`sed -e s/:/-/g $a`   #Replace all colons in the string $a with dashes

and then use the name $b.tar instead of $a.zip (I'd use the .tar instead 
of .zip for a tar archive. Helps with consitency)?

I know I used that line in order to strip empty spaces from filenames, 
replacing them with underscores.

Hope this helps!
-Henrik W Lund



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?40F97CA1.90500>