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

  • SEARCH
  • Home
  • 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 8511851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:07:17+00:00 2026-06-11T04:07:17+00:00

I am currently trying to sanitize some log files so they are in an

  • 0

I am currently trying to sanitize some log files so they are in an easier format to read, and have been trying to use the gnu cut command, which works fairly well, although I cannot really think of a good way to remove the [INFO] part of the string

logs/logs/server_1283258036.log:2010-08-31 23:06:51 [INFO] <NateMar> where?!
logs/logs/server_1281904775.log:2010-08-15 22:59:53 [INFO] <BoonTheMoon> §b<BoonTheMoon>§ohhhhhh
logs/logs/server_1282136782.log:2010-08-18 16:27:32 [INFO] <pinguin> <pinguin>§F :/
logs/logs/server_1282136782.log:2010-08-18 16:27:37 [INFO] <TotempaaltJ> <TotempaaltJ>§F That helped A LOT
logs/logs/server_1282136782.log:2010-08-18 16:27:37 [INFO] <Rizual> §b<Rizual>§F hm?
logs/logs/server_1282136782.log:2010-08-18 16:29:10 [INFO] <pinguin> <pinguin>§F bah
logs/logs/server_1282136782.log:2010-08-18 16:29:35 [INFO] <TotempaaltJ> <TotempaaltJ>§F Finished my houses 
logs/logs/server_1282136782.log:2010-08-18 16:29:40 [INFO] <TotempaaltJ> <TotempaaltJ>§F or whatever
logs/logs/server_1282136782.log:2010-08-18 16:30:47 [INFO] <Rizual> §b<Rizual>§So much iron
logs/logs/server_1282136782.log:2010-08-18 16:30:58 [INFO] <TotempaaltJ> <TotempaaltJ>§F Ah yes, furnaces don't work.o
logs/logs/server_1282136782.log:2010-08-18 16:31:01 [INFO] <Rizual> §b<Rizual>§F They do
logs/logs/server_1282136782.log:2010-08-18 16:31:06 [INFO] <TotempaaltJ> <TotempaaltJ>§F Hm
logs/logs/server_1282136782.log:2010-08-18 16:31:08 [INFO] <Rizual> §b<Rizual>§F just need to use /lighter
logs/logs/server_1282136782.log:2010-08-18 16:31:12 [INFO] <Valrix> <Valrix>§FNotch fixed them?

I would ultimately want to get the strings down to something that resembles the following (keep in mind that the logs are in two formats, the older format which has 2 copies of the names, as can be seen in the bulk of the logs above, and also the newer format, which only has the name in there once (can be seen in the first log line, the <natemar> one))

2010-08-31 23:06:51 <NateMar> where?!    
2010-08-15 22:59:53 <BoonTheMoon> ohhhhhh (this one would require both the same editing as above, plus removal of the "extra" name §b<BoonTheMoon>§)    

How should I go about doing this? Have thought about using awk, although I’m having a difficult time getting a grip on how that would work, so not sure how to set up something to do that. Any help would be greatly appreciated, 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-06-11T04:07:18+00:00Added an answer on June 11, 2026 at 4:07 am

    More takes on this, in sed, awk and bash:

    [ghoti@pc ~]$ cat text
    logs/logs/server_1283258036.log:2010-08-31 23:06:51 [INFO] <NateMar> where?!
    logs/logs/server_1281904775.log:2010-08-15 22:59:53 [INFO] <BoonTheMoon> §b<BoonTheMoon>§ohhhhhh
    
    [ghoti@pc ~]$ sed 's/^[^:]*://;s/[[][^]]*[]] //' text
    2010-08-31 23:06:51 <NateMar> where?!
    2010-08-15 22:59:53 <BoonTheMoon> §b<BoonTheMoon>§ohhhhhh
    
    [ghoti@pc ~]$ awk '{sub(/^[^:]+:/,""); $3=""} 1' text
    2010-08-31 23:06:51  <NateMar> where?!
    2010-08-15 22:59:53  <BoonTheMoon> §b<BoonTheMoon>§ohhhhhh
    
    [ghoti@pc ~]$ while read line; do line=${line#*:}; echo "${line/\[*\] }"; done < text
    2010-08-31 23:06:51 <NateMar> where?!
    2010-08-15 22:59:53 <BoonTheMoon> §b<BoonTheMoon>§ohhhhhh
    

    While these are simple, they may be imperfect for the sake of shortness. For example, the awk script, by eliminating the third “word”, leaves spaces that delimit the now-null word.

    Note that as “elegant” as one-liners may seem for quick jobs, it’s usually a better idea to be explicit with your code, especially when you have to deal with unknown input data or if you won’t be inspecting your results immediately after you run things.

    This is harder to read, but could be much safer, depending on your input:

    [ghoti@pc ~]$ awk '$3~/^[[].+[]]$/{$3="";sub(/  /," ")} {sub(/^[^:]+:/,"")} 1' text
    2010-08-31 23:06:51 <NateMar> where?!
    2010-08-15 22:59:53 <BoonTheMoon> çb<BoonTheMoon>çohhhhhh
    

    For the bash script, you’d be safer to use a character class rather than a glob:

    [ghoti@pc ~]$ shopt -s extglob
    [ghoti@pc ~]$ while read line; do line=${line#*:}; echo "${line/\[+([[:upper:]])\] /}"; done < text
    2010-08-31 23:06:51 <NateMar> where?!
    2010-08-15 22:59:53 <BoonTheMoon> çb<BoonTheMoon>çohhhhhh
    

    Note that the extglob shopt option lets you use more advanced pattern matching inside the parameter replacement pattern. man bash and look for Pathname Expansion for details.

    UPDATE:

    You’ve added a new requirement to your question that wasn’t there originally. Here’s how you can achieve your new requirement with awk:

    awk '$3~/^[[].+[]]$/{$3="";sub(/  /," ")} {sub(/^[^:]+:/,"")} $3~/^<.+>$/{sub(/^(§b)?<[[:alpha:]]+>§/,"",$4)} 1' text
    

    This simply removes coloured nicknames from the 4th string, if the 3rd string looks like a bracketed nickname. This works for the sample you posted, but only you can determine whether this will work for you.

    And with bash:

    shopt -s extglob
    while read date time tag nick line; do
      printf "%s %s %s %s\n" "${date#*:}" "$time" "$nick" "${line/#*([^< ])$nick??}"
    done < text
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently trying to filter some information from a file we have coming to
I am experimenting with filter_input and filter_var and I am currently trying to sanitize
Im currently trying to downlaod a audio track from a WCF, i need some
Im currently trying to learn some stuff about encryption, it's algorithms and how it
I am currently trying to write some code that will accept some FTP details,
I currently trying to use an Object Relational Mapper for CodeIgniter and I'm experiencing
I am currently trying to complete a project where the specifications are to use
Im currently trying to read an XML file and populate an observable collection, but
im currently trying to work on a small adventure game use Pygame of course,
Currently trying to find a way to do the following inside some form of

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.