Need to extract specific pattern from logfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to extract specific pattern from logfile
# 1  
Old 01-04-2009
Need to extract specific pattern from logfile

Log File:

Attempting to contact (DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname1.com)(PORT=1521)) )(CONNECT_DATA=(SID=database1)(SRVR=DEDICATED)))

Attempting to contact (DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname2.com)(PORT=1521)) )(CONNECT_DATA=(SID=database2)(SRVR=DEDICATED)))

Attempting to contact (DESCRIPTION_LIST=(DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname 3.com)(PORT=1521)))(CONNECT_DATA=(SID=database3)(SRVR=DEDICATED)))(DESCRIPTION=(SOURCE_ROUTE=OFF)(AD DRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname3.com)(PORT=1522)))(CONNECT_DATA=(SID=database3)(SRV R=DEDICATED))))

Attempting to contact (DESCRIPTION_LIST=(DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname 4.com)(PORT=1521)))(CONNECT_DATA=(SID=database4)(SRVR=DEDICATED)))(DESCRIPTION=(SOURCE_ROUTE=OFF)(AD DRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname4.com)(PORT=1522)))(CONNECT_DATA=(SID=database4)(SRV R=DEDICATED))))

I need output like below: I have tried regular expression /awk -- not able to get expected output (below one)

HoST PORT SID
hostname1.com 1521 database1
hostname2.com 1521 database2
hostname3.com 1522 database3
hostname4.com 1522 database4

Can someone please help me on this?
# 2  
Old 01-04-2009
Code:
perl -00ne'
  print  join " ",
        /HOST=([^)]+)\)
        \(PORT=(\d+).*?
          SID=(\w+)/x, "\n" 
  ' logfile

If the records are not separated by blank lines, remove the 00 option and argument.

Last edited by radoulov; 01-04-2009 at 01:30 PM..
# 3  
Old 01-07-2009
perfect - it works!

Quote:
Originally Posted by radoulov
Code:
perl -00ne'
  print  join " ",
        /HOST=([^)]+)\)
        \(PORT=(\d+).*?
          SID=(\w+)/x, "\n" 
  ' logfile

If the records are not separated by blank lines, remove the 00 option and argument.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract whole word preceding a specific character pattern with first occurence of the pattern

Hello. Here is a file contents : declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern =I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '=' Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies

2. UNIX for Dummies Questions & Answers

Search specific string logfile specific date range

Hi, I have logfile like this.. === 2014-02-09 15:46:59,936 INFO RequestContext - URL: '/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko': Unsupported with Accept-Encoding header === 2015-02-09... (8 Replies)
Discussion started by: kishk
8 Replies

3. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

4. Shell Programming and Scripting

Extract the last 10 minutes from logfile

Any better way to extract the last 10 minutes from logfile? Dec 18 09:41:18 aaa Dec 18 09:46:29 aa Dec 18 09:48:39 vvv Dec 18 09:48:54 bbb Dec 18 09:54:47 bbb Dec 18 09:55:33 fcf Dec 18 09:55:38 ssdf Dec 18 09:57:58 sdsds Dec 18 09:58:10 sdsd Dec 18 10:00:50 sdsd Dec 18... (5 Replies)
Discussion started by: timmywong
5 Replies

5. Shell Programming and Scripting

Extract three substrings from a logfile

I have a log file like below. 66.249.73.11 - - "UCiZ7QocVqYAABgwfP8AAHAA" "US" "Mediapartners-Google" "-" www.mahashwetha.com.sg "GET... (2 Replies)
Discussion started by: Tuxidow
2 Replies

6. Shell Programming and Scripting

Extract Specific pattern - log file

Hello everyone, I am on AIX (6.1). I can only use shell (ksh) script. I can't do this on my own, so will do my best to explain my needs.I also do not know what is the best idea to make it work, so here is what I am thinking, but I may wrong. I need help to extract info on... (3 Replies)
Discussion started by: Aswex
3 Replies

7. Shell Programming and Scripting

extract specific line if the search pattern is found

Hi, I need to extract <APPNUMBER> tag alone, if the <college> haas IIT Chennai value. college tag value will have spaces embedded. Those spaces should not be suppresses. My Source file <Record><sno>1</sno><empid>E0001</empid><name>Rejsh suderam</name><college>IIT ... (3 Replies)
Discussion started by: Sekar1
3 Replies

8. Shell Programming and Scripting

Script to extract line from logfile

Hi , Can someone help me,I am not well versed with scripting,it is very urjent. Need a script in perl or shell for the following task. The logfile contains several entries of which one particular string to be searched and that complete line has to be removed and copied to another file to... (25 Replies)
Discussion started by: garryt21@rediff
25 Replies

9. Shell Programming and Scripting

Extract specific pattern from a file

Hi All, I am a newbie to Shell Scripting. I have a File The Server Name XXX002 ------------------------- 2.1 LAPD Iface Id Link MTU Side ecc_3_1 4 Up 512 User ecc_3_2 5 Up 512 User The Server Name XXX003 ------------------------- 2.1 LAPD (4 Replies)
Discussion started by: athreyavc
4 Replies

10. HP-UX

extract field of characters after a specific pattern - using UNIX shell script

Hello, Below is my input file's content ( in HP-UX platform ): ABCD120672-B21 1 ABCD142257-002 1 ABCD142257-003 1 ABCD142257-006 1 From the above, I just want to get the field of 13 characters that comes after 'ABCD' i.e '120672-B21'... . Could... (2 Replies)
Discussion started by: jansat
2 Replies
Login or Register to Ask a Question