.sh check for sufix g or m on size field

Chad Perrin perrin at apotheon.com
Tue Jul 13 23:46:35 UTC 2010


On Mon, Jul 12, 2010 at 08:58:05AM -0700, Chip Camden wrote:
> Quoth Aiza on Monday, 12 July 2010:
> > Sorry miss send, was not done yet.
> > 
> > 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.*$//'`
> > 
> > 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.
> > 
> > Thanks
> > _______________________________________________
> > freebsd-questions at freebsd.org mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> > To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
> 
> It sounds like what you want is simply:
> 
> sed 's/[gm]//'
> 
> Or am I missing something?

I get the impression it's something more like this:

    sed 's/[gm]$//'

I'm not sure, but there may be a need to check whether the rest of the
line is solely numeric, too.  The original question was not exactly clear
on that point.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20100713/5497c693/attachment.pgp


More information about the freebsd-questions mailing list