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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:03:51+00:00 2026-06-09T08:03:51+00:00

I am writing a perl script to parse tab delimited data from standard input.

  • 0

I am writing a perl script to parse tab delimited data from standard input.

The script removes leading and trailing whitespace, blanks out any field that has the string “NULL” and re-formats date columns from “MMM DD YYYY HH:MM:SS:SSSAM” format to “YYYYMMDD” format.

Sample Input:

93092   Apr  1 2010 12:00:00:000AM      59668370.60702875
22341   Apr  1 2010 12:00:00:000AM      51309196.84639429
27844   Apr  1 2010 12:00:00:000AM      NULL
150465  Apr 22 2010 12:00:00:000AM      19706190.97586569
119364  Jul  20 2010 12:00:00:000AM      16335977.41009162

Target Output:

93092|20100401|59668370.60702875
22341|20100401|51309196.84639429
27844|20100401|
150465|20100422|19706190.97586569
119364|20100720|16335977.41009162

The script takes an argument representing the column(s) which have dates that need conversion. In the sample above, I would invoke with “1” as the param, since the 2nd column is the date that needs conversion. More than one column would be represented by a comma separated list.

This is what I’ve been able to do so far.

#!/usr/bin/perl
my @date_cols = split(/,/, $ARGV[0]);

while (<STDIN>) {
   my @fields = split(/\t/, $_, -1);
   for (@fields) {
      s/^\s+//;
      s/\s+\z//;
      s/^NULL\z//;
   }
   for (@fields[@date_cols]) {
##NEED HELP WITH DATE FORMATTING
   }

   print(join('|', @fields), "\n");
}
  • 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-09T08:03:53+00:00Added an answer on June 9, 2026 at 8:03 am

    Using Time::Piece is simple and easily provides you with the date formmating. The strptime function lets you define the pattern you want to work with; the strftime function lets you produce the output format desired. Consider:

    use Time::Piece;
    my $date = "Apr  1 2012 12:00:00AM";
    my $t = Time::Piece->strptime($date,"%b %d %Y %H:%M:%S%p");
    print $t->strftime("%Y%m%d\n");
    

    A nice feature of this approach is that it doesn’t matter whether one or two spaces separate the month and day fields; the results are the same.

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

Sidebar

Related Questions

I'm writing a Perl script that reads data from the infamous /dev/input/event* and I
I am writing a Perl script that needs to extract some data from an
I am writing Perl script. In that I have to read log4j.xml file from
I'm writing a Perl script that runs 4 simultaneous, identical processes with different input
I'm writing a Perl script and would like to use a n-ary tree data
First question from a long time user. I'm writing a Perl script that will
I'm writing a Perl script and I need to capture some lines from a
I am writing a Perl script that can run both from command line and
I have a Perl script for writing data to a MySQL DB, runs fine.
Here is the simple perl script fetching data from SQL. Read data and write

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.