Skip to content

Instantly share code, notes, and snippets.

@sebge2emasphere
Created August 10, 2018 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebge2emasphere/8ca8a7b2afd9f47306150670afa193f9 to your computer and use it in GitHub Desktop.
Save sebge2emasphere/8ca8a7b2afd9f47306150670afa193f9 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
my $tenantColumn = 1;
my $outputFile = "output.csv";
my $inputCsv = Text::CSV->new({ })
or die "Cannot use Text::CSV ($!)";
my $outputCsv = Text::CSV->new({eol => $/ })
or die "Cannot use Text::CSV ($!)";
my $inputFile = $ARGV[0]
or die "Need to get CSV file on the command line\n";
open(my $dataIn, '<', $inputFile)
or die "Could not open '$inputFile' $!\n";
open my $dataOut, '>', $outputFile
or die "Cannot open $outputFile ($!)";
my $lineNumber = 0;
while (my $line = <$dataIn>) {
chomp $line;
if ($inputCsv->parse($line)) {
my @fields = $inputCsv->fields();
if($lineNumber > 0){
$fields[$tenantColumn] = "my tenant" ;
}
$outputCsv->print($dataOut, \@fields);
$lineNumber++;
} else {
warn "Line could not be parsed: $line\n";
}
}
close $dataOut
or die "Failed to close $outputFile ($!)";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment