Need to grep certain entry out of log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to grep certain entry out of log file
# 1  
Old 06-07-2013
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
Code:
$ cat $MW_HOME/user_projects/domains/IDMDomain/servers/wls_ods?/logs/wls_ods1-diagnostic.log  | grep DIP-10219

I get this output.
Code:
[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.
Code:
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!

Last edited by exm; 06-07-2013 at 05:51 PM..
# 2  
Old 06-07-2013
Please use codes tags as required by forum rules!

Try this:
Code:
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.
# 3  
Old 06-07-2013
I assume I have to substitute "file" with the actual file name? This returns no rows:

Code:
$ 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


Last edited by exm; 06-07-2013 at 05:50 PM..
# 4  
Old 06-10-2013
Any thoughts? Thanks!
# 5  
Old 06-10-2013
What's the output of the sed command acting on your file alone (without the pipe)?
# 6  
Old 06-10-2013
Quote:
Originally Posted by RudiC
What's the output of the sed command acting on your file alone (without the pipe)?
No output:

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

# 7  
Old 06-10-2013
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitor and capture the latest entry from the log file

Hi, I want to monitor a log file using tail -f command and search for a specific string on the most recent entry from the file. If the search string matches with the most recent or last line from the file, I want send an email to the people with the message. tail -f service.log|tail -n 1 ... (5 Replies)
Discussion started by: svajhala
5 Replies

2. Shell Programming and Scripting

Selecting latest entry in the log file

Hi there I am trying to write a script where I will need to look for a specific word in the log file and I am aware this can be done by grep for example. As there will be multiple entries for this I want to grep the last one to enter the log... how would I go about this - would I have to use... (5 Replies)
Discussion started by: simpsa27
5 Replies

3. UNIX for Dummies Questions & Answers

How to grep for first entry in a file?

Hello friends, I have a question. Sometimes I have to search for an entry in a file that is repeated thousands of times. Can you tell me how to search so that i get limited results? For example: file: myfile.txt grep "hello world" myfile.txt this above grep will generate 5000... (4 Replies)
Discussion started by: DallasT
4 Replies

4. Shell Programming and Scripting

How to grep a log file for words listed in separate text file?

Hello, I want to grep a log ("server.log") for words in a separate file ("white-list.txt") and generate a separate log file containing each line that uses a word from the "white-list.txt" file. Putting that in bullet points: Search through "server.log" for lines that contain any word... (15 Replies)
Discussion started by: nbsparks
15 Replies

5. Shell Programming and Scripting

[awk] grep a part of filename as entry file

hi all, i need to combine these files into one csv file. Bounce_Mail_Event_Daily_Report_01_Jul_2012.csv Bounce_Mail_Event_Daily_Report_02_Jul_2012.csv Bounce_Mail_Event_Daily_Report_03_Jul_2012.csv Bounce_Mail_Event_Daily_Report_04_Jul_2012.csv... (10 Replies)
Discussion started by: makan
10 Replies

6. Shell Programming and Scripting

How to write a new entry at the beginning of a log file instead of at the end?

Hi Ladies and Gents, Explanation of my question with an example: Let's consider the script: backup_every_hour.sh #!/bin/bash rsync -auv $dir $backup_dir >> backup_every_hour_script.log Each time this script is called there will be a new entry at the end of the file... (1 Reply)
Discussion started by: freddie50
1 Replies

7. UNIX for Dummies Questions & Answers

grep first occurrence but continue to next entry in patternfile

I have 1300 files (SearchFiles0001.txt, SearchFiles0002.txt, etc.) , each with 650,000 lines, tab-delimited data. I have a pattern file, with about 1000 lines with a single word. Each single word is found in the 1300 files once. If I grep -f PatternFile.txt SearchFiles*.txt >OutputFile.txt... (2 Replies)
Discussion started by: newhavendweeb
2 Replies

8. UNIX Desktop Questions & Answers

How to grep for password file entry

How would I grep for password file entry without using grep 'username' /etc/passwd? perhaps with who? I want to create alias that will find the password file entry regardless of the user who is using it. Thanks (4 Replies)
Discussion started by: alis
4 Replies

9. UNIX for Dummies Questions & Answers

grep for password file entry

How would I grep for password file entry without using grep 'username' /etc/passwd? perhaps with who? I want to create alias that will find the password file entry regardless of the user who is using it. I am trying to get the same exact line from the file entry like: Name : Password : UserID... (7 Replies)
Discussion started by: alis
7 Replies

10. Shell Programming and Scripting

Grep table entry problem

Hi, I have a table which looks like this Line a b c 0 10 0 0 1 0 0 2 0 ... (1 Reply)
Discussion started by: ahjiefreak
1 Replies
Login or Register to Ask a Question