Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 456261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:27:12+00:00 2026-05-12T22:27:12+00:00

I’m attempting to write a bash script to parse out the following log file

  • 0

I’m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined). Note that Samual has rejoined.

[Sun Nov 15 14:12:50 2009] [GAME: Tower Defense Join Fast!] player [Samual|192.168.1.115] joined the game
[Sun Nov 15 14:12:54 2009] [GAME: Tower Defense Join Fast!] deleting player [Samual]: has left the game voluntarily
[Sun Nov 15 14:12:57 2009] [GAME: Tower Defense Join Fast!] player [Jack|192.168.1.121] joined the game
[Sun Nov 15 14:13:04 2009] [GAME: Tower Defense Join Fast!] player [NoobLand|192.168.1.153] is trying to join the game but is banned by IP address
[Sun Nov 15 14:13:04 2009] [GAME: Tower Defense Join Fast!] [Local]: User [NoobLand] was banned on server [www.example.com] on 2009-11-04 by [Owner] because [].
[Sun Nov 15 14:13:13 2009] [GAME: Tower Defense Join Fast!] player [Jones|192.168.1.178] joined the game
[Sun Nov 15 14:13:21 2009] [GAME: Tower Defense Join Fast!] player [Arnold|192.168.1.126] joined the game
[Sun Nov 15 14:13:35 2009] [GAME: Tower Defense Join Fast!] [Local]: Autokicking player [Arnold] for excessive ping of 131.
[Sun Nov 15 14:13:35 2009] [GAME: Tower Defense Join Fast!] deleting player [Arnold]: was autokicked for excessive ping of 131
[Sun Nov 15 14:13:44 2009] [GAME: Tower Defense Join Fast!] [Lobby] [Jones]: !chekme
[Sun Nov 15 14:13:44 2009] [GAME: Tower Defense Join Fast!] non-spoofchecked user [Jones] sent command [chekme] with payload []
[Sun Nov 15 14:13:45 2009] [GAME: Tower Defense Join Fast!] [Local]: Waiting for 4 more players before the game will automatically start.
[Sun Nov 15 14:14:05 2009] [GAME: Tower Defense Join Fast!] player [Samual|192.168.1.116] joined the game

To give me a list of players currently in the room like this (I can probably use tr for case switch):

'jack','jones','samual'

When a player joins it will say “player [Playername|PlayerIP] joined the game” (you can ignore the IP.
When a player leaves it will say “deleting player [Playername]: Some Reason

While I know how to get at both of these lists individually, I need to combine them to somehow figure out who is still in the room, and order is important because they can rejoin. Can anyone help me with this?

I have this sed statement to give me the players who have joined:

sed -n 's/\[.*\] \[GAME: .*\] player \[\(.*\)|.*\] joined the game/\1/p`

and this to give me a list of leavers:

sed -n 's/\[.*\] \[GAME: .*\] deleting player \[\(.*\)\].*/\1/p'

But don’t know how to combine the two, or to put the ticks and commas in the list of players.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:27:13+00:00Added an answer on May 12, 2026 at 10:27 pm

    Part of solving a problem effectively is choosing the right tool. In this case, trying to do it all in bash is probably a worse choice than something like Perl or Python, because:

    • it will be more complicated to implement, debug and maintain
    • it will use many more processes
    • the performance is likely to be poor

    If you would like help to write this in a more appropriate language, just ask.

    …later…

    OK, you chose Perl….

    You could certainly do everything which you’re trying to do in Perl itself. However, as you’re unfamiliar with it, I’ve put together a little toy program which should do what you’re after.

    #!/usr/bin/perl -w
    
    use strict;
    
    my %present;
    
    while (<>) {  # loop over input lines
      if (/player \[(.*?)(?:\|\d+\.\d+\.\d+\.\d+)?\]:? (.*)/) {
        my $player = $1;
        my $event = $2;
    
        if ($event eq "joined the game") {
          $present{$player} = 1;
        } elsif ($event eq "has left the game voluntarily") {
          delete $present{$player};
        } elsif ($event =~ /^was autokicked/) {
          delete $present{$player};
        }
      }
    }
    
    foreach (sort keys %present) {
      print "$_\n";
    }
    

    The output produced looks like this:

    $ ./analyse inputfile
    Jack
    Jones
    Samual
    

    and you may wish to call it something like this from your bash script:

    tail -1000 ghost.log | ./analyse
    

    or even:

    playerspresent=`tail -1000 ghost.log | ./analyse`
    

    I’ve tried to keep the Perl program as simple as is sensible. The only “difficult” bit is the regular expression. Essentially, it loops over the lines of input, trying to decide whether each line represents someone joining or leaving. If joining, the username is added to the %present hash; if leaving, it is removed. At the end, the names are listed in order.

    Is this enough to get you back on track?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Actually, Symphony is a widely used CMS in PHP see:… May 14, 2026 at 8:08 pm
  • Editorial Team
    Editorial Team added an answer I found out the reason - it was missing the… May 14, 2026 at 8:08 pm
  • Editorial Team
    Editorial Team added an answer Off the top of my head, there are a couple… May 14, 2026 at 8:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.