Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm looking for some suggestion to convert the .asn1 (CDR Data) to CSV to load to tables. As per current approach I'm using informatica B2B parser to parse the ASN file to XML than using XSD loading to Greenplum tables.

I hope Perl can do these operations in a better way; for a day we are receiving a ~30k ASN file which is a very big file.

For converting XML to CSV (Confused about how to convert XML to CSV using xmlstarlet on OS X?) not sure this approach works or if there's any plugin in Perl.

ASN files are binary files, second step is XML to CSV.

Sample XML:

<?xml version="1.0" encoding="windows-1252"?>
<RadiusCDR_Parent>
<RadiusCDR>
<accountingRequest>
<userName>1200099344</userName>
<nasIPAddress>0A490010</nasIPAddress>
<nasPort>0</nasPort>
<serviceType>2</serviceType>
<framedProtocol>1</framedProtocol>
<framedIPAddress>64702E70</framedIPAddress>
<vendorSpecificExt>
<cisco>
<subAttributeID>1</subAttributeID>
<vendorLength>26</vendorLength>
<data>connect-progress=Call Up</data>
</cisco>
<cisco>
<subAttributeID>1</subAttributeID>
<vendorLength>19</vendorLength>
<data>portbundle=enable</data>
</cisco>
<cisco>
<subAttributeID>250</subAttributeID>
<vendorLength>17</vendorLength>
<data>S10.73.0.17:785</data>
</cisco>
<cisco>
<subAttributeID>253</subAttributeID>
<vendorLength>11</vendorLength>
<data>I0;153521</data>
</cisco>
<cisco>
<subAttributeID>253</subAttributeID>
<vendorLength>11</vendorLength>
<data>O0;559080</data>
</cisco>
</vendorSpecificExt>
<callingStationID>503c.c433.b8df</callingStationID>
<nasIdentifier>INMUNVMBXXXXNB0001AG3WAG001.ril.com</nasIdentifier>
<acctStatusType>3</acctStatusType>
<acctDelayTime>0</acctDelayTime>
<acctInputOctets>0257B1</acctInputOctets>
<acctOutputOctets>0887E8</acctOutputOctets>
<acctSessionID>009B51EC</acctSessionID>
<acctAuthentic>1</acctAuthentic>
<acctSessionTime>2012</acctSessionTime>
<acctInputPackets>1187</acctInputPackets>
<acctOutputPackets>1130</acctOutputPackets>
<eventTimeStamp>140E0A0F 123B0E</eventTimeStamp>
<nasPortType>5</nasPortType>
<nasPortID>0/0/0/902</nasPortID>
</accountingRequest>
</RadiusCDR>
<RadiusCDR_Parent>

I would like that other than Cisco information rest all also is in CSV.

share|improve this question
    
There are proper XML handling libraries for Perl. Problem is that there are unlimited ways to represent tabular data in an XML file. Do you have a representative example for the XML and how it should look as CSV? –  Anthon Nov 15 '14 at 14:01
    
Please show us an example of your input files and your desired output. Ideally, show us both the ASN and the XML files. I don't see any reason to go through an intermediate XML if what you want is csv. Also, what are CDR data? Remember that we don't work in your field. To me CDR is a Complementarity determining region coding region, are you working with sequences? –  terdon Nov 15 '14 at 14:22
    
Guys Updated the Question , CDR - Call data records (System generated binary information) mostly in the format of .asn cant be readable by text editor. –  William R Nov 15 '14 at 14:37
    
There's a comment in this thread: stackoverflow.com/questions/3353004/… that says there is no such tool to convert ASN.1 to CSV. Your Q is still confusing to me. Are you just looking for XML to CSV or something else? –  slm Nov 15 '14 at 15:04
    
My entire purpose is to convert (asn to csv) step 1: asn1 to xml and step 2 : xml to csv , But if not possible to convert asn to csv lookig for xml to csv conversion in perl. –  William R Nov 15 '14 at 15:36

1 Answer 1

I got the below Code , for different set of XML file to CSV.

Code:

#!/usr/bin/perl

# Script to illustrate how to parse a simple XML file
# and pick out all the values for a specific element, in
# this case all the titles.

# use strict;
use XML::Simple;
use Data::Dumper;

# create object
$xml = new XML::Simple (KeyAttr=>[]);

# read XML file
$data = $xml->XMLin("test1.xml");


my $booklist = XMLin('test1.xml');    #booklist is the array 
# print Dumper($booklist);

foreach my $FreemanFees (@{$booklist->{FreemanFees}}) {


    print 
    $FreemanFees->{SdcLoanFacilityNumber} , "," , 
    $FreemanFees->{DealId} ,",", 
    $FreemanFees->{Tranche}->{SdcDealNumber} , "," , 
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{ManagerNumberForFreemanFee}, ",",
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{currencyId},",",
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{sdcCurrencyCode} , "," , 
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{scale}, ",",
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{content} , "," ,"\n" ;
    }

But how to fetch next elements if i have more ?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.