From owner-freebsd-questions@FreeBSD.ORG Mon Jul 12 15:35:38 2010 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 92A10106564A for ; Mon, 12 Jul 2010 15:35:38 +0000 (UTC) (envelope-from swell.k@gmail.com) Received: from mail-ey0-f182.google.com (mail-ey0-f182.google.com [209.85.215.182]) by mx1.freebsd.org (Postfix) with ESMTP id 224248FC18 for ; Mon, 12 Jul 2010 15:35:37 +0000 (UTC) Received: by eyh6 with SMTP id 6so650883eyh.13 for ; Mon, 12 Jul 2010 08:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version:content-type; bh=R9IY5jNIWVSsksvBSUvSOgdIIvUrBFvD9VJL5tYIFFU=; b=okLkFoZ2Aq9NNUeG50IB7Zr+AIoILNsOqVkvU5TfLCadt2OkxwxME3lqshTEwhe0V3 /62ZuSB4SqfBmNMeXOmpQb2lunNTLa2eQEhLYAeQV4zP01yLD4eJFWusrIBrtUNjrOP9 BrOSOgwY3EUeg5aGTQWKwTTDWSVk8b/K077J4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; b=OaqePkCu0MiiToETmtwuOT3QqPVsg2Rmyqe3kAtFILrreOvdmFAXr0qaIibkqavcAZ IJ1P5564JSW3MsOCWuV5yxOq5ATi/40xumuKI6Y8SJOC3jGX4abTUtWVATHaOutBWjaX gdcOpoFoA2WsW0GCbHp3k8v+TsvBUvFqDT/xY= Received: by 10.213.31.141 with SMTP id y13mr10607476ebc.34.1278948934185; Mon, 12 Jul 2010 08:35:34 -0700 (PDT) Received: from localhost ([78.47.29.82]) by mx.google.com with ESMTPS id v59sm38067047eeh.16.2010.07.12.08.35.30 (version=SSLv3 cipher=RC4-MD5); Mon, 12 Jul 2010 08:35:33 -0700 (PDT) From: Anonymous To: Aiza References: <4C3B26B4.1000208@comclark.com> Date: Mon, 12 Jul 2010 19:35:06 +0400 In-Reply-To: <4C3B26B4.1000208@comclark.com> (Aiza's message of "Mon, 12 Jul 2010 22:29:08 +0800") Message-ID: <867hl0ems5.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "questions@freebsd.org" Subject: Re: .sh check for sufix g or m on size field X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jul 2010 15:35:38 -0000 Aiza writes: > Have a .sh script that accepts an -s sparse file size. > Only 2 suffix's are valid m and g. > > Been trying to get this line of code to strip out just the single > letter. But it strips the letter and every thing to the right of it. > > Timagesize=`echo-n "${imagesize}" | sed 's/g.*$//'` You didn't state what's your input. I guess smth like following will do strip() { local size= if printf >&- 2>&- %g ${size:=${1%[gm]}}; then echo "it's a \`$size' without suffix" else echo "$1 has invalid suffix" fi } $ strip 17m it's a `17' without suffix $ strip 33g it's a `33' without suffix $ strip 25gm 25gm has invalid suffix > > I plan to strip just the m or g if its there and the result should be > numeric. If not numeric know invalid suffix. > > Need help with the sed syntax. Or if there is better way I want to > learn it.