Using grep to Find Things in the IDM Trace Log



If you use Identity Manager, you are experienced with reading a DSTrace output with the DirXML and DirXML Drivers flags on. (If you do not recognize what I am talking about, then you are not experienced with IDM - sorry.)

Finding the event you want is usually easy with a simple search. So, search in your browser on the web version of Dstrace, and that's fine for finding specific events.

However, one big issue is this: as you get into more complex issues, you may need to see all occurences of a particular attribute. The structure of an XDS document that IDM uses does not lend itself well to simple searching with a tool like grep.

Here we move over to a Unix-style OS, since they handle text files so very, very well. There are stacks of tools available, but for the purist, less (or more), grep, and cat are all great tools. But if you grep for Full Name (trying to find all instances of the Full Name attribute in the document, which may have thousands of instances) you will get back just the line the search string occurs on.


I finally got around to reading the man page for grep and noticed two really great switches: -B and -C. For example, '-B 4' will show the 4 lines before the string if found, and '-C 4' will show the 4 lines following the line the string is found on.

So this command:

cat logfile.log | grep Surname -B 4 -C 4 | less 

will show each time Surname appears, from 4 lines before to 4 lines after.

This makes finding what you need much easier!


How To-Best Practice
Comment List