LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-04-2005, 02:52 AM   #1
(TPM) Croaker
LQ Newbie
 
Registered: Jan 2005
Posts: 7

Rep: Reputation: 0
Text Parser


I'm not a newbie to Linux in general, but I have had little to no experience writing programs or scripts. I was hoping that somebody may be able to give me a heads-up on how to accomplish this.

I am running a game server on my Xandros box as a test server for my clan. I want to be able to easily see how much, if any, traffic I am getting on the server. The game creates a log file with entries that are easily identifiable each time someone joins the server. However, since I have the server running all the time I have to wade through a lot of other stuff to see these login messages.

The log looks like this:

Quote:
1606:18 InitGame: \.Admin\=DREAD= Croaker\.Email\xxxxxxx\.Location\So. Cal\.Website\xxxxxxxx\g_gametype\bel\g_timeoutsallowed\0\gamename\CoD:United Offensive\mapname\mp_uo_dawnville\protocol\22\scr_allow_jeeps\1\scr_allow_tanks\1\shortversion\1.51\ sv_allowAnonymous\0\sv_floodProtect\1\sv_hostname\Croaker's STOCK Practice Server\sv_maxclients\14\sv_maxPing\200\sv_maxRate\5000\sv_minPing\0\sv_privateClients\4\sv_punkbuste r\1\sv_pure\1
1606:35 J;0;5;[TBC] Raven
1606:49 ShutdownGame:
The entry that I am looking to extract is the:

Quote:
1606:35 J;0;5;[TBC] Raven
So, what I need is a text file parser that will allow me to find the line that includes the
Quote:
J;
characters as they are unique, and then extract that entire line and place it into the output file. The output file does not need to be formatted for the web, nor is it being saved to a database, just a regular text file would be fine.

I did a number of searches through Google, but most of what I found created either the web-format or database-format output files. Or else they were specific to certain types of log files or configuration files for input.

Can anyone point me to a decent parser program or script that is flexible enough to do what I want?

Any help would be appreciated.

Thanks.
 
Old 10-04-2005, 10:51 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Here's one solution using awk (there are probably a lot more):

awk '$2 ~ /^J;.*/ { print $0 }' game.log

awk checks to see if field 2 (there's a space between the beginning time and the next entry) starts with a capital J, folowed by whatever($2 ~ /^J;.*/). If so, print entire line ((print $0)).

A sample run with the given logfile fill example (stored in game.log) and the output redirected (put in) output.file:

$ awk '$2 ~ /^J;.*/ { print $0 }' game.log > output.file
$ cat output.file
1606:35 J;0;5;[TBC] Raven

Hope this helps.
 
Old 10-04-2005, 10:55 PM   #3
(TPM) Croaker
LQ Newbie
 
Registered: Jan 2005
Posts: 7

Original Poster
Rep: Reputation: 0
druuna,

Thanks a lot. That is all that I wanted to do. I dropped your commands into a Bash script (I think that's what it's called) and it works perfectly. I really appreciate the information as well as the quick response.

Thanks again.

Take Care.
Croaker.
 
Old 10-05-2005, 01:18 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Or
Code:
awk ' $2 ~ /^J;/ ' game.log
if you're as lazy as me ;} ... because to print the whole line is
awks default behaviour if no other actions are given.


Cheers,
Tink

Last edited by Tinkster; 10-05-2005 at 01:19 AM.
 
  


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
checking for XML::Parser... configure: error: XML::Parser perl module is required for kornerr Linux - General 11 11-16-2008 08:24 AM
DTD's Parser? trscookie Linux - Software 0 11-07-2005 05:55 PM
XML Parser bulkman Linux - Software 6 04-29-2005 08:01 AM
How to test a parser? koyi Programming 0 10-27-2004 04:31 AM
URI parser nodger Programming 1 05-03-2004 11:56 AM


All times are GMT -5. The time now is 08:50 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration