autogen.sh: Don't use "egrep -o", use "sed"

"egrep -o" isn't portable and not available on OpenBSD, for example. So
let's use sed instead to get the automake version. The expression used
now is less specific but should work as well ...
autogen.sh: Check for autoconf/automake wrapper scripts

For example OpenBSD uses a "autoconf" and "automake" wrapper script which
tells the user to set AUTOCONF_VERSION and AUTOMAKE_VERSION environment
variables. This patch enhances autogen.sh to not detect these wrapper
scripts as regular autoconf/automake commands but to set the required
environment variables after detecting the real "command-X.Y" commands.

Tested on OpenBSD 5.1.