• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

data manipulation, change date format in perl

Sample data.csv

"09/05/2001","101","01","abc"
"09/05/2001","107","02","def"
"09/05/2001","109","03","ghi"
"09/06/2001","111","01","jkl"
"09/06/2001","113","02","mno"
"09/06/2001","115","03","pqr

perl script to get the outputdata.csv to be
05-Sep-2001-101,abc
05-Sep-2001-107,def
05-Sep-2001-109,ghi
06-Sep-2001-111,jkl
06-Sep-2001-113,mno
06-Sep-2001-115,pqr

Thanks
Begunix
0
Begunix
Asked:
Begunix
  • 2
1 Solution
 
Adam314Commented:
my @mon=qw(nul Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
while(<>) {
      my @f=split(/[",\/]+/);
      print join("-", $f[2],$mon[$f[1]],@f[3,4]),",$f[6]\n";
}
0
 
BegunixAuthor Commented:
Thanks for the reply. I apologize for the confusion.
The sample data in test.csv
09/07/2001,101,1700,abc
09/08/2001,103,1800,cde
10/04/2001,105,0100,fgh
11/03/2001,107,1700,hij
11/12/2001,301,1900,klm
12/05/2001,501,1700,nop
01/01/2002,601,0500,qrs

output file (output.csv) should be as given below.
07-Sep-2001-17-00,abc,101
08-Sep-2001-18-00,cde,103
04-Oct-2001-01-00,fgh.105
03-Nov-2001-17-00.hij,107
12-Nov-2001-19-00,klm,301
05-Dec-2001-17-00,nop,501
01-Jan-2002-05-00,qrs,601

Thanks
Begunix
0
 
Adam314Commented:
my @mon=qw(nul Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
while(<>) {
      chomp;
      my @f=split(/[",\/]+/);
      print "$f[1]-$mon[$f[0]]-$f[2]-".substr($f[4],0,3)."-".substr($f[4],2,2).",$f[5],$f[3]\n";
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now