Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Best method of munging CSV data - using Text::CSV::Simple?

by billie_t (Sexton)
on Feb 09, 2006 at 00:59 UTC ( #528981=note: print w/replies, xml ) Need Help??


in reply to Best method of munging CSV data - using Text::CSV::Simple?

I just thought I'd post the finished work of art:
#! /usr/bin/perl #parsing Exchange output file to create address aliases use strict; use warnings; my($infile) = ("C:\\recipient.txt"); my($outfile) = ("C:\\outfile.txt"); use Text::CSV::Simple; open(OUTPUT, ">$outfile") or die "Can't open $outfile : $!"; my $parser = Text::CSV::Simple->new; $parser->want_fields(1, 2, 3); my @data = $parser->read_file($infile); foreach my $line (@data) { # process only accounts that contain SMTP addesses + if ($line->[0] =~ m/SMTP:/i) { my $user = $line->[1]; my $server = substr(($line->[2]), -6); #split up the line that contains all the email addresses my @smtp = split(';', $line->[0]); foreach my $part (@smtp) { # do not process anything that is not an SMTP address # (exclude fax & X400) if ($part =~ m/SMTP:/i) { $part = substr($part, 5); print OUTPUT ("$user\@$server \t $part\n"); } } } } # CSVDE command used on domain controller to # generate recipient information for users in domain # Dumps the user name, all proxy addresses # and the home mailbox server - it WON'T exclude the DN. # csvde -m -n -g -f "C:\recipient.txt" -r "(|(&(objectClass=user)(obje +ctCategory=person))(objectClass=groupOfNames)(objectClass=msExchDynam +icDistributionList))" -o "distinguishedName, DN" -L "name,proxyAddres +ses,msExchHomeServerName"
Output is exactly what I wanted. Thanks for all your help, guys!

Replies are listed 'Best First'.
Re^2: Best method of munging CSV data - using Text::CSV::Simple?
by Scott7477 (Chaplain) on Feb 06, 2007 at 00:11 UTC
    Here is my code that uses Text::CSV::Simple; the goal was to parse a NYSE price list from the Wall Street Journal.
    use strict; use Text::CSV::Simple; #usage wsj2csv AMEX091806.txt my ($filename) = shift; print $filename."\n"; print "What is the trading date(MMDDYY)?"; my $traddt = <STDIN>; print $traddt."\n"; my $parser = Text::CSV::Simple->new; $parser->want_fields(1, 2, 3, 4, 5, 6, 8); my @data = $parser->read_file($filename); my $datalines = @data; print $datalines."is number of rows.\n"; for my $row(@data) { my @line = @$row; foreach my $row1(@line) { print $row1.","; } print "\n"; }

    I intend to add more functionality to this; but this thread was helpful to me in getting the parser to work

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://528981]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2021-10-22 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?