earth tech

[software and hardware technology originating from or otherwise pertinent to planet earth]

use these buttons to share this blog on portal sites:

Add to Google

Monday, July 16, 2007

 

Bash du+sort Script

This is a one-liner that shows something about why grep has behaved so strangely in the past when we've tried to feed it regular expressions as the pattern to match:

  du -h | grep  "^[1-9]\+\.[0-9]\+[M]" | sort 

The trick here was to add the backslashes ('\') in front of the plus signs ('+'). apparenlty grep interprets the '+' literally if it is not escaped.

Note A: the Debian-blows-goats version of grep is not built with support for Perl regular expressions (bug #15051), which figures, since the Debian-POS developers only seem to know Python.

Note B: it apparenlty makes no difference to [this version] grep if the quote delimiters used in the above command are single- or double-quotes [this is counter-intuitive, since use of single quotes typically means no escape characters are needed], but the quotes must be there for the command to work - leaving them out causes the command to emit no output.

Labels: , , , ,

Archives

2006/12   2007/01   2007/05   2007/06   2007/07   2007/08   2007/10   2008/01   2008/02   2008/03   2008/05   2008/11   2008/12   2009/01   2009/02   2009/03   2009/04   2009/05   2009/07   2009/09   2009/10   2009/11   2009/12   2010/01  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]