2007-07-16

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.