Hello everyone,
I'm currently working on an automated process which extract user info from AD with csvde, then do some treatments with perl scripts, convert the csv file into xls in order to do some modifications by a specific user in Excel, then convert the xls to csv, format it in a specific type in order to be imported to the company's phonebook (an intranet app with SQL Database), and, finally, convert it to ldf in order to import the modifications for every user into the ActiveDirectory again (so that we won't have to do the modifications every time an extraction is done).
Great isn't it ? Well the thing is I'm far from being a Perl Script Expert so I have some problems in some of my scripts...
And I'm currently stuck with a stupid thing: I'm trying to drop a column in my csv when encountering a specific String (as an example let's say I want to drop the "Distinguishedname" column from my AD Extract). I have found and modificated a Script that drops a column if every data contained in the column (ie for every line) is equal to my string, but not if the string is encountered once.
Do you have a solution please ?
If you have also the solution for dropping the line IF a String is encountered in the column named "example" -in the header line-, I'm fully interested !!!!
Here is the code I'm trying to adapt:
--------------------------
#!/usr/bin/perl
use warnings;
use strict;
my $file = 'input-light.csv';
open my $FH, '<', $file or die "Cannot open '$file' $!";
my @headers = map 1, split /,/, <$FH>, -1;
my @keep = ( undef ) x @headers;
while ( <$FH> ) {
chomp;
my @fields = split /,/, $_, -1;
die "Error: expected " . @headers . " fields but reading " .
@fields . " fields instead.\n"
if @headers < @fields;
for my $i ( 0 .. $#fields ) {
$keep[ $i ] = $i if $fields[ $i ] ne '"Distinguishedname"';
}
exit 0 if @headers == grep defined, @keep;
}
close $FH;
@keep = grep defined, @keep;
( $^I, @ARGV ) = ( '.back2', $file );
while ( <> ) {
chomp;
print join( ',', ( split /,/, $_, -1 )[ @keep ] ), "\n";
}
__END__
------------------
Thanks by advance,
Bastien