Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-04-2005, 01: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:

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:

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
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.

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

Rep: Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391

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, 09:55 PM   #3
(TPM) Croaker
LQ Newbie
Registered: Jan 2005
Posts: 7

Original Poster
Rep: Reputation: 0

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.
Old 10-05-2005, 12:18 AM   #4
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
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.


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


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 07:24 AM
DTD's Parser? trscookie Linux - Software 0 11-07-2005 04:55 PM
XML Parser bulkman Linux - Software 6 04-29-2005 07:01 AM
How to test a parser? koyi Programming 0 10-27-2004 03:31 AM
URI parser nodger Programming 1 05-03-2004 10:56 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:20 PM.

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