Howard Chu wrote:
This works with gawk: #! /bin/sh # $OpenLDAP: pkg/ldap/tests/scripts/acfilter.sh,v 1.13 2008/01/07 23:20:16 kurt Exp $ grep -v '^#' | awk 'BEGIN{FS="\n";RS=""} {j=0; for (i=1; i<=NF; i++){ if ($i ~ /^ /){ x[j] = x[j] "\n" $i; } else { j++; x[j] = $i } } print x[1]; delete x[1]; j=asort(x); for (i=1; i<=j; i++){ print x[i]; } delete x; print "" }'(all as a single line of text) Unfortunately the asort() function is a GNU extension, so I think we have to pipe to the sort command instead: grep -v '^#' | awk 'BEGIN{FS="\n";RS=""}{j=0; for (i=1; i<=NF; i++){ if ($i ~ /^ /) { x[j] = x[j] "\n" $i; } else { j++; x[j] = $i }} print x[1]; for (i=2; i<=j; i++){print x[i] | "sort +0";} delete x; close("sort +0"); print ""}'
Oops. Except piping to sort loses the field boundaries, so continuation lines are messed up.
-- -- Howard Chu CTO, Symas Corp. http://www.symas.com Director, Highland Sun http://highlandsun.com/hyc/ Chief Architect, OpenLDAP http://www.openldap.org/project/
