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 8406991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:15:57+00:00 2026-06-09T23:15:57+00:00

I have a following simple script for parsing out dates from irc logs (created

  • 0

I have a following simple script for parsing out dates from irc logs (created by irssi)

#!/bin/bash                                                                                  
query=$1

grep -n $query logfile > matches.log 
grep -n "Day changed" logfile >> matches.log

cat matches.log | sort -n

It produces output like:

--- Day changed Tue Jul 03 2012
--- Day changed Wed Jul 04 2012
--- Day changed Thu Jul 05 2012
16:54 <@Hamatti> who let the dogs out
--- Day changed Fri Jul 06 2012
--- Day changed Sat Jul 07 2012
--- Day changed Sun Jul 08 2012
12:11 <@Hamatti> dogs are fun

But since I’m only interested in finding out dates for actual matches, I’d like to filter out all those

--- Day changed XXX XXX dd dddd

lines where they don’t follow by timestamp on the next line. So the example should output

--- Day changed Thu Jul 05 2012
16:54 <@Hamatti> who let the dogs out
--- Day changed Sun Jul 08 2012
12:11 <@Hamatti> dogs are fun

to get rid of all the disinformation that’s not useful.

edit.
After the answer by T. Zelieke I realised that I could make this more of a one-liner so I use the following now to save logfile from being iterated twice.

query=$1
egrep "$query|Day changed" logfile |grep -B1 "^[^-]" |sed '/^--$/d'
  • 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-09T23:15:58+00:00Added an answer on June 9, 2026 at 11:15 pm
    grep -B1 "^[^-]" data |sed '/^--$/d'
    

    This uses grep to filter lines that do NOT start with a dash ("^[^-]"). -B1 asks to print the immediate line before a match.
    Unfortunately grep separates then each match (pair of two lines) by an -- line. Therefore I pipe the output through sed to get rid of those superflouos lines.

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

Sidebar

Related Questions

I have following rather simple query select count(*) from tbl t1, tbl t2 For
I have the following simple shell script: # get all servers from config sshservers=`node
I have the following simple script for backing up my website files and db.
i have the following simple script <input class=input type=text name=password style=color: #797272; value= <?php
I have the following simple script. However, it incorrectly gives the counter result to
it is the problem, i can't undertand anyway. i have the following simple script
I have the following simple python test script that uses Suds to call a
Let's say I have the following, very simple block of code: <script> function hasVal(field)
I have the following simple script to test the mkdir() function in PHP: <?php
i have the following simple script <input type=button onclick=document.getElementById('a').innerHTML = '<option>something</option>';/> <select id=a style=width:

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.