Need to grep certain entry out of log file

This one is a bit too challenging for me... Hopefully you guys can help.

Let's say I have a log file called:
"$MW_HOME/user_projects/domains/IDMDomain/servers/wls_ods?/logs/wls_ods1-diagnostic.log"

In this log file I want to search for "DIP-10219". When I execute this

$ cat $MW_HOME/user_projects/domains/IDMDomain/servers/wls_ods?/logs/wls_ods1-diagnostic.log  | grep DIP-10219

I get this output.

[2013-06-07T11:06:08.071-04:00] [wls_ods1] [ERROR] [DIP-10219] [oracle.dip.ORA_EBSAD] [tid: oracle.ldap.odip.web.DIPSyncWriterThread] [userId: <anonymous>] [ecid: 0000JwQp2v533Fw5GFP5if1HgDcU000002,1:26283] [APP: DIP#11.1.1.2.0] Exception creating entry : cn=aala\, steve (ora-ns),cn=users,dc=oracle,dc=com.
[2013-06-07T11:06:08.691-04:00] [wls_ods1] [ERROR] [DIP-10219] [oracle.dip.ORA_EBSAD] [tid: oracle.ldap.odip.web.DIPSyncWriterThread] [userId: <anonymous>] [ecid: 0000JwQp2v533Fw5GFP5if1HgDcU000002,1:26283] [APP: DIP#11.1.1.2.0] Exception creating entry : cn=lui\, john (ora),cn=users,dc=oracle,dc=com.

Based on this output, I need to write a wrapper that executes something with the output in red above.

ldapdelete -h $OIDHOST -p $OIDPORT -D $OIDUSER -w $OIDPWD -c -v dn "cn=aala\, steve (ora-ns),cn=users,dc=oracle,dc=com"
ldapdelete -h $OIDHOST -p $OIDPORT -D $OIDUSER -w $OIDPWD -c -v dn "cn=lui\, john (ora),cn=users,dc=oracle,dc=com"

So I would like to know, how to:

  1. Create a loop to search through the logfile
  2. Pass the entries to a second command (ldapdelete), remove everything before "cn=" and after "=com"

Hopefully you can help me!

Please use codes tags as required by forum rules!

Try this:

sed -rn '/DIP-10219/ s/^.*[^,](cn=.*com).*$/\1/p' file | while read CMD; do echo ldapdelete -h \$OIDHOST -p \$OIDPORT -D \$OIDUSER -w \$OIDPWD -c -v dn \"$CMD\"; done
ldapdelete -h $OIDHOST -p $OIDPORT -D $OIDUSER -w $OIDPWD -c -v dn "cn=aala, steve (ora-ns),cn=users,dc=oracle,dc=com"
ldapdelete -h $OIDHOST -p $OIDPORT -D $OIDUSER -w $OIDPWD -c -v dn "cn=lui, john (ora),cn=users,dc=oracle,dc=com"

Once you're happy with what you see, you can remove the echo command and the escapes for the $signs. If your sed can't be made accept the extended regexes, you'll have to escape the parentheses in the substitute command.

I assume I have to substitute "file" with the actual file name? This returns no rows:

$ sed -rn '/DIP-10219/ s/^.*[^,](cn=.*com).*$/\1/p' $MW_HOME/user_projects/domains/IDMDomain/config/fmwconfig/servers/*/dms_config.xml | while read CMD; do echo ldapdelete -h \$OIDHOST -p \$OIDPORT -D \$OIDUSER -w \$OIDPWD -c -v dn \"$CMD\"; done

Any thoughts? Thanks!

What's the output of the sed command acting on your file alone (without the pipe)?

No output:

$ sed -rn '/DIP-10219/ s/^.*[^,](cn=.*com).*$/\1/p' $MW_HOME/user_projects/domains/IDMDomain/config/fmwconfig/servers/*/dms_config.xml
$ 

This is a file different from the one you posted in #1. Are you sure it has the same structure and contains lines that have DIP-10219 in them?

My bad! The original string works like a charm. THANK YOU!