Concord/dci2csv

here is a little script i wrote to change DCI rules foles to csv formated files.


 * 1) !/bin/perl

use strict; use warnings; use Getopt::Long;

Getopt::Long::config qw(no_ignore_case);

my ( $inputFile, $outputAllFields, $searchKey, $outputFields ); our @foundSegments; {

$outputFields = 'name,deviceSpeedIn,deviceSpeedOut'; my $needHelp; GetOptions( 	'dciInFile=s' 		=> \$inputFile,		'findField=s'		=> \$searchKey,		'showFields=s'		=> \$outputFields,		'listAllFields'		=> \$outputAllFields,		'help|h|H|?|HELP' 	=> \$needHelp	); die usage if $needHelp; }


 * 1) Data collection
 * 2)  using an input file
 * 3)  else quit
 * 1)  else quit

if ($inputFile){

findVars($inputFile); } else { die usage }


 * 1) Data output
 * 2) 	if request for keys print all keys
 * 3) 	else print results
 * 1) 	else print results

if ($outputAllFields) { foreach ( @foundSegments ) { foreach (keys %$_) { print "$_, "; } print "\n"; }

} else { foreach my $found (@foundSegments) { foreach my $showKey (split /,/, $outputFields) { print "$found->{$showKey},"; } print "\n"; } }

sub usage { return <<USAGETEXT; usage: $0 -dciInFile filename -dciInFile filename is the dci file you want to scan the following options are also availble [ -findField fieldName ] this is the search key to be used (by default all elements will be returned) [ -showFields field names ] feilds to output (default is name,deviceSpeedIn,deviceSpeedOut) [ -listAllFields ] list avalible fields [ -help] this help text USAGETEXT }

sub findVars {
 * 1) find infomation form Concord's dci files
 * 2) usage:
 * 3)  findVars("key to search in","value to search for")
 * 4) output:
 * 5)  an aray of Hashes containing all matched segments and keys
 * 1) output:
 * 2)  an aray of Hashes containing all matched segments and keys

my ($dciFile, $segmentFieldKey, %segment, $segmentFieldValue, %segmentFields, $nullVar); my $inElementSection;


 * 1) read in dci filename from parent

$dciFile=$_[0] || die qq( FindVars function: Missing dciInfile value $!);

chomp $dciFile;

open(DCIFILE, "<$dciFile") || die "FindVars function: can not open : $!";

foreach my $line () { chomp $line;

if ( $line =~ /^FN,Elements,/ ) { $line =~ s/FN\,Elements\,//g; our $i="0"; foreach (split(/\,/,$line)) { $i++; $segmentFields{ $i } = $_; } next; };  if ( $line =~ /^DS,,Elements,/ ) {$inElementSection=1; next;} #marks start of elements if ( $line =~ /^DE/ ) {$inElementSection=0; next;} #marks end of elements if ($inElementSection==1) { our $ii="0"; foreach (split(/\,/,$line)) { if ($_ =~ /^$/) {$segment{$segmentFields{$ii}}="void";} $ii++; $segment{$segmentFields{$ii}}=$_; }   push @foundSegments,{%segment}; next; } } close DCIFILE;

return (@foundSegments);     # return to main ruteen

}

Back to Concord Index