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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:56:40+00:00 2026-05-15T16:56:40+00:00

In Perl I am trying to read a log file and will print only

  • 0

In Perl I am trying to read a log file and will print only the lines that have a timestamp between two specific times. The time format is hh:mm:ss and this is always the third value on each log. For example, I would be searching for lines that would fall between 12:52:33 to 12:59:33

I am new to Perl and have no idea which route to take to even begin to program this. I am pretty sure this would use some type of regex, but for the life of me I cannot even begin to fathom what that would be. Could someone please assist me with this.

Also, to make this more difficult I have to do this with the core Perl modules because my company will not allow me to use any other modules until they have been tested and verified there will be no ill effects on any of the systems the script may interact with.

  • 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-15T16:56:41+00:00Added an answer on May 15, 2026 at 4:56 pm

    In pseudocode, you’d do something like this:

    • read in the file line by line:
      • parse the timestamp for this line.
      • if it’s less than the start time, skip to the next line.
      • if it’s greater than the end time, skip to the next line!
      • else: this is a line you want: print it out.

    This may be too advanced for your needs, but the flip-flop operator .. immediately comes to mind as something that would be useful here.

    For reading in a file from stdin, this is the conventional pattern:

    while (my $line = <>)
    {
         # do stuff...
    }
    

    Parsing a line into fields can be done easily with split (see perldoc -f split). You will probably need to split the line by tabs or spaces, depending on the format.

    Once you’ve got the particular field (containing the timestamp), you can examine it using a customized regexp. Read about those at perldoc perlre.

    Here’s something which might get you closer:

    use strict;
    use warnings;
    
    use POSIX 'mktime';
    my $starttime = mktime(33, 52, 12);
    my $endtime = mktime(33, 59, 12);
    
    while (my $line = <>)
    {
        # split into fields using whitespace as the delimiter
        my @fields = split(/\s+/, $line);
    
        # the timestamp is the 3rd field
        my $timestamp = $fields[2];
    
        my ($hour, $min, $sec) = split(':', $timestamp);
        my $time = mktime($sec, $min, $hour);
    
        next unless ($time < $starttime) .. ($time > $endtime);
        print $line;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying Perl on Mac. I have to read an RTF text file. the
I am trying to read values from an input file in Perl. Input file
So I am trying to read an XML file into a string in Perl
I trying to run a Perl script to read an YAML file, but I
Here is what im trying to achieve. I have a perl script that looks
In Perl, I'm trying to read a file line by line and process each
So I'm trying to write a perl script to read in a file encoded
I have a perl script that is used to monitor databases and I'm trying
I'm trying to read a text file (using perl) where each line has several
I am trying to write a script that will read a remote sitemap.xml and

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.