string manipulation in a shell script

Matthew Seaman m.seaman at infracaninophile.co.uk
Sat Jul 17 03:21:32 PDT 2004


On Sat, Jul 17, 2004 at 04:33:27PM +0800, 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,

Well, to get date(1) to spit out a date-time string without any
unfortunate punctuation, try something like:

    % date +%Y%m%d%H%M%S

See strftime(3) for details of all the % escapes you can use with
date(1).

On the other hand, tar(1) has an option --force-local which causes it
to ignore colons in filenames as indicating a remote tape drive.
Nb. that's gnu tar, which is the standard tar in all 4.x and any
5.x-RELEASE -- 5.2-CURRENT will shortly switch to bsdtar, and that
will probably work differently.

	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20040717/b168ffc1/attachment.bin


More information about the freebsd-questions mailing list