0

Dear Experts,
Here i have bit stuck with logic to create text to CSV file creation. pls help me to this code.
Thanks in Advance,
Senthil. V

[U]input file[/U]

"OC192-11,OC192:ESS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1"
"OC192-11,OC192:SESS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1"
"OC192-11,OC192:SEFSS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1"
"OC192-11,OC192:CVL,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1"
[U]OUTPUT as CSV [/U]
ESS                      SESS                       SEFSS                   CVL   
"OC192-11,OC192:ESS,0",  "OC192-11,OC192:SESS,0",   "OC192-11,OC192:SEFSS,0", OC192-11,OC192:CVL,0,
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by d5e5
0

I would need some more information on your input file. Is the data file always only 4 lines long, or can there be more lines? If there are more lines, are they always grouped together in sets of 4? Are those lines always in the same order (ESS, SESS, SEFSS, and CVL), or are they mixed up? Maybe just a larger set of example data would help.

0
#!/usr/bin/perl
use strict;
use warnings;

print "ESS\tSESS\tSEFSS\tCVL\n";

while(<DATA>){
    s/"//g;#Remove all double quotes
    my @fields = m/(.+?,)/g;
    print chr(34), @fields[0..2], chr(34), "\t";
}

__DATA__
"OC192-11,OC192:ESS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1"
"OC192-11,OC192:SESS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1"
"OC192-11,OC192:SEFSS,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1"
"OC192-11,OC192:CVL,0,COMPL,NEND,RCV,1-DAY,02-11,00-00,1"

Running the above prints the following to STDOUT

ESS	SESS	SEFSS	CVL
"OC192-11,OC192:ESS,0,"	"OC192-11,OC192:SESS,0,"	"OC192-11,OC192:SEFSS,0,"	"OC192-11,OC192:CVL,0,"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.