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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:37:59+00:00 2026-05-14T21:37:59+00:00

I have a application generating logs in every 5 sec. The logs are in

  • 0

I have a application generating logs in every 5 sec. The logs are in below format.

11:13:49.250,interface,0,RX,0
11:13:49.250,interface,0,TX,0
11:13:49.250,interface,1,close,0
11:13:49.250,interface,4,error,593
11:13:49.250,interface,4,idle,2994215
and so on for other interfaces...

I am working to convert these into below CSV format:

Time,interface.RX,interface.TX,interface.close....
11:13:49,0,0,0,....

Simple as of now but the problem is, I have to get the data in CSV format online, i.e as soon the log file updated the CSV should also be updated.

What I have tried to read the output and make the header is:

#!/usr/bin/perl -w
use strict;

use File::Tail;
my $head=["Time"];
my $pos={};
my $last_pos=0;
my $current_event=[];

my $events=[];

my $file = shift;
$file = File::Tail->new($file);

while(defined($_=$file->read)) {
     next if $_ =~ some filters;

     my ($time,$interface,$count,$eve,$value) = split /[,\n]/, $_;
     my $key = $interface.".".$eve;

     if (not defined $pos->{$eve_key}) {
          $last_pos+=1;
          $pos->{$eve_key}=$last_pos;
          push @$head,$eve;
        }
        print join(",", @$head) . "\n";
}

Is there any way to do this using Perl?

  • 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-14T21:38:00+00:00Added an answer on May 14, 2026 at 9:38 pm

    Module Text::CSV will allow you to both read and write CSV format files. Text::CSV will internally use Text::CSV_XS if it’s installed, or it will fall back to using Text::CSV_PP (thanks to Brad Gilbert for improving this explanation).

    Grouping the related rows together is something you will have to do; it is not clear from your example where the source date goes to.

    Making sure that the CSV output is updated is primarily a question of ensuring that you have the output file line buffered.


    As David M suggested, perhaps you should look at the File::Tail module to deal with the continuous reading aspect of the problem. That should allow you to continually read from the input log file.

    You can then use the ‘parse’ method in Text::CSV to split up the read line, and the ‘print’ method to format the output. How you combine the information from the various input lines to create an output line is a mystery to me – I cannot see how the logic works from the example you give. However, I assume you know what you need to do, and these tools will give you the mechanisms you need to handle the data.

    No-one can do much more to spoon-feed you the answer. You are going to have to do some thinking for yourself. You will have a file handle that can be continuously read via File::Tail; you will have a CSV structure for reading the data lines; you will probably have another CSV structure for the written output; you will have an output file handle that you ensure is flushed every time you write. Connecting these dots is now your problem.

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

Sidebar

Related Questions

We have a web application that is generating some 3-5 parallel threads every five
I have an application generating a really heavy big log file every days (~800MB
I have a customer who's Classic ASP application is generating ASP_0147 errors. The first
I have an MVC application view that is generating quite a large HTML table
We are a lead generating company and have developed one application where our customers
I have a WinForm application which is generating CSV files. I give the user
I have a WPF application and I use external library for generating documents. This
I have an application where I am generating many Bitmap objects. Once I create
I have created application using TSQL and libraries. Right now I am generating clients
I have an application that prints by generating text files with embedded printer codes,

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.