From owner-freebsd-questions@FreeBSD.ORG Sat Jul 17 10:23:02 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EEA2B16A4CE for ; Sat, 17 Jul 2004 10:23:02 +0000 (GMT) Received: from mail.broadpark.no (mail.broadpark.no [217.13.4.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9C80243D53 for ; Sat, 17 Jul 2004 10:23:02 +0000 (GMT) (envelope-from henrik.w.lund@broadpark.no) Received: from [10.0.0.3] (52.80-202-129.nextgentel.com [80.202.129.52]) by mail.broadpark.no (Postfix) with ESMTP id D548516EA; Sat, 17 Jul 2004 12:23:32 +0200 (MEST) Message-ID: <40F97CA1.90500@broadpark.no> Date: Sat, 17 Jul 2004 12:23:13 -0700 From: Henrik W Lund User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040616 X-Accept-Language: nb, en-us, en MIME-Version: 1.0 To: Kathy Quinlan References: <40F8E457.1030303@kaqelectronics.dyndns.org> In-Reply-To: <40F8E457.1030303@kaqelectronics.dyndns.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-questions@freebsd.org Subject: Re: string manipulation in a shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jul 2004 10:23:03 -0000 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