Created
June 13, 2016 14:42
-
-
Save Woody2143/6b0d3e0d98d3418af16a19967109dbff 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
telephoneNumber: 4045554400 | |
mobile: 2145555000 | |
reversedPhone:0005555412 | |
reversedPhone:0044555404 | |
title: Operations Engineer | |
cn: Smith, John | |
telephoneNumber: 6785554400 | |
mobile: 3015555000 | |
reversedPhone:0005555103 | |
reversedPhone:0044555876 | |
title: Operations Engineer | |
cn: Doe, John |
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
cat example.ldif | ./fix.pl | |
cn: Smith, John^title: Operations Engineer^phone: 4045554400^phone: 2145555000^mobile: 2145555000^telephoneNumber: 4045554400^ | |
cn: Doe, John^title: Operations Engineer^phone: 6785554400^phone: 3015555000^mobile: 3015555000^telephoneNumber: 6785554400^ |
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/env perl | |
use warnings; | |
use strict; | |
use Modern::Perl; | |
my $count = 0; | |
my @people; | |
my $blank = 0; | |
while (<STDIN>) { | |
chomp; | |
my $line = $_; | |
if ($line =~ m/reversedPhone:/) { | |
$blank = 0; | |
my @reversed = split ":", $line; | |
my $phone = reverse scalar $reversed[1]; | |
#say "phone: $phone^"; | |
push @{$people[$count]}, "phone: $phone"; | |
} elsif ($line eq "") { | |
if ( $blank == 0) { | |
$count++; | |
$blank = 1; | |
} else { | |
next; | |
} | |
} else { | |
$blank = 0; | |
#say "$line^"; | |
push @{$people[$count]}, "$line"; | |
} | |
} | |
for my $line (@people) { | |
my @person = reverse @{$line}; | |
say map {$_ . "^"} @person; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment