
Chris Charley
User
Jul 29, 2014, 4:44 PM
Post #6 of 9
(1483 views)
|
Re: [malalo] Data processing from text file
[In reply to]
|
Can't Post
|
|
Picking up some of BillKSmith's suggestions, (use warnings, 3 argument open), this script should do what you want.
#!/usr/bin/perl use strict; use warnings; my $file = "test.txt"; # test.txt in current directory # create filehandle open my $fh, '<', $file or die "Unable to open $file $!"; while (<$fh>) { chomp; tr/"//d; # eliminate the quotation marks my ($dir, $read, $write) = split /\t/; my %seen = map {$_ => 1} split /, /, $write; $read = join ", ", grep !$seen{$_}, split /, /, $read; # restore the quotation marks $_ = qq{"$_"} for $read, $write; print join("\t", $dir, $read, $write), "\n"; } close $fh or die "Unable to close $file $!"; __END__ *** contents of test.txt DirectoryName "Administrators, DOMAIN\User1, DOMAIN\User2, NT AUTHORITY\Authenticated Users" "Administrators, DOMAIN\User1, DOMAIN\User2" (I'm not sure about the #!/usr/bin/perl line) This prints:
DirectoryName "NT AUTHORITY\Authenticated Users" "Administrators, DOMAIN\User1, DOMAIN\User2"
|