LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-18-2011, 05:57 PM   #1
free_ouyo
Member
 
Registered: Mar 2004
Location: Belgium
Distribution: Ubuntu
Posts: 133

Rep: Reputation: 15
Extract portion of text - IRC Log


Hello,

I have a lot of files containing chat-log (IRC) and would like to extract information out of these files.

File sample
Code:
Session Start: Sat Apr 03 15:06:29 2010
Session Ident: XXX
[15:06] XXX is ~X@host-85-85-85-154.isp.be * XXX
[15:06] XXX on #channel1 #channel2 #channel3 
[15:06] XXX using *.undernet.org The Undernet Underworld
[15:06] XXX End of /WHOIS list.
-
[15:06] <Me> Hello
[15:07] <Me> How are you ?
[15:15] <Me> Bye
Session Close: Sat Apr 03 15:16:52 2010

Session Start: Sat Apr 03 15:47:53 2010
Session Ident: XXX
[16:21] XXX No such nick
[16:21] XXX End of /WHOIS list.
-
[16:30] <Me> Hello
[16:31] <Me> How are you ?
[16:32] <XXX> Hello, fine and you ?
[16:32] <Me> ....
Session Close: Sat Apr 03 17:21:35 2010
I would like to extract in a separate file the info between the 'Session Start' and the 'Session Close' and isolate the /WHOIS informations at top of bottom of conversation like

File1
Code:
Session Start: Sat Apr 03 15:06:29 2010
Session Ident: XXX
[15:06] <Me> Hello
[15:07] <Me> How are you ?
[15:15] <Me> Bye
Session Close: Sat Apr 03 15:16:52 2010

[15:06] XXX is ~X@host-85-85-85-154.isp.be * XXX
[15:06] XXX on #channel1 #channel2 #channel3 
[15:06] XXX using *.undernet.org The Undernet Underworld
[15:06] XXX End of /WHOIS list.
File 2
Code:
Session Start: Sat Apr 03 15:47:53 2010
Session Ident: XXX
[16:30] <Me> Hello
[16:31] <Me> How are you ?
[16:32] <XXX> Hello, fine and you ?
[16:32] <Me> ....
Session Close: Sat Apr 03 17:21:35 2010

[16:21] XXX No such nick
[16:21] XXX End of /WHOIS list.
I can find the interesting lines with egrep commands but don't see how to extract info and put it correctly into separate files ...

Any help is welcome. Thanks.
 
Old 07-18-2011, 07:46 PM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,411

Rep: Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873
Well its only a quick knock up, but you get the idea:
Code:
awk 'BEGIN{i=1}/Start/,/Close/{if($2 == "XXX")whois = (whois?whois:"")"\n"$0;else if(!/-/)print > "FILE"i}/Close/{print whois > "FILE"i++;whois=""}' file
 
1 members found this post helpful.
Old 07-19-2011, 03:50 AM   #3
free_ouyo
Member
 
Registered: Mar 2004
Location: Belgium
Distribution: Ubuntu
Posts: 133

Original Poster
Rep: Reputation: 15
Thanks it's working great and I can integrate it into a script and found the way to handle the case with $2.

Last edited by free_ouyo; 07-19-2011 at 05:01 AM. Reason: Found solution
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
marking-yanking/deleting a portion of text not working in vim7 vineet7kumar Linux - Newbie 1 11-09-2008 04:43 PM
Extract text from messages log brianmcgee Programming 1 09-17-2008 08:35 AM
Shell script to remove certain portion of the text kushalkoolwal Programming 4 08-24-2008 11:17 PM
Extract certain text info from text file xmrkite Linux - Software 30 02-26-2008 11:06 AM
How do I log all changes to a portion of the filesystem? Ziv Linux - Security 3 07-12-2004 08:59 PM


All times are GMT -5. The time now is 10:09 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration