Created
August 10, 2018 06:16
-
-
Save sebge2emasphere/8ca8a7b2afd9f47306150670afa193f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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