# If you'd like to omit non-matching lines from the result; add ';d' to the end of the expression.
sed -E 's/(<cfldap[^>]* name ?= ?")(.*?)("[^>]*)( sort ?= ?"(.*?)")(.*?>)/$1unsortedResults$3$6\n<cfquery dbtype="query" name="$2">SELECT * FROM unsortedResults ORDER BY $5<\/cfquery>\n/gi;t' <<< "<!--- petofma 20090716: new CED LDAP server now wants applications to authenticate! --->
<CFLDAP server=\"#session.comldapserver#\" port=\"#session.comldapport#\" action=\"QUERY\" name=\"results\" start=\"ou=People, o=#session.comldaproot#\"
username=\"#server.comLdapLogin#\" password=\"#server.comLdapPass#\"
scope=\"onelevel\" filter=\"(&#filterstring#(recordStatus=a)#Iif(IsDefined(\"dgfish_only\"),DE(\"(sourceOrganisation=COM)(dg=MARE)\"),DE(\"\"))#)\" sort=\"uid\" attributes=\"dn,employeeNumber,ecSYSPERNumber,gestelNumber,uid,title,cn,dg,departmentNumber,telephoneNumber,facsimilenumber,l,mail,physicalDeliveryOfficeName,sourceOrganisation,employeeType,contractExpiryDate,recordStatus,modifytimestamp,source,manager\">
<CFOUTPUT>
<P>Found <b>#results.RecordCount# User#Iif(results.RecordCount EQ 1,DE(\"\"),DE(\"s\"))#</b> matching your search criteria:
</CFOUTPUT>
<cfif IsDebugMode()>
<cfdump var=#results#>
</cfif>
"
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for SED, please visit: https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html