Advertisement
Guest User

IBM Communities Perl parse script

a guest
Dec 27th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.95 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # @copyright(disclaimer)
  3. #
  4. # Licensed Materials - Property of IBM
  5. # 5724-L31
  6. # (C) Copyright IBM Corp. 2017. All Rights Reserved.
  7. #
  8. # US Government Users Restricted Rights
  9. # Use, duplication or disclosure restricted by GSA ADP Schedule
  10. # Contract with IBM Corp.
  11. #
  12. # DISCLAIMER OF WARRANTIES :
  13. #
  14. # Permission is granted to copy and modify this Sample code, and to
  15. # distribute modified versions provided that both the copyright
  16. # notice, and this permission notice and warranty disclaimer appear
  17. # in all copies and modified versions.
  18. #
  19. # THIS SAMPLE CODE IS LICENSED TO YOU "AS-IS".
  20. # IBM  AND ITS SUPPLIERS AND LICENSORS  DISCLAIM
  21. # ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, IN SUCH SAMPLE CODE,
  22. # INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES
  23. # OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
  24. # WILL IBM OR ITS LICENSORS OR SUPPLIERS BE LIABLE FOR ANY DAMAGES ARISING
  25. # OUT OF THE USE OF  OR INABILITY TO USE THE SAMPLE CODE, DISTRIBUTION OF
  26. # THE SAMPLE CODE, OR COMBINATION OF THE SAMPLE CODE WITH ANY OTHER CODE.
  27. # IN NO EVENT SHALL IBM OR ITS LICENSORS AND SUPPLIERS BE LIABLE FOR ANY
  28. # LOST REVENUE, LOST PROFITS OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
  29. # CONSEQUENTIAL,INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS
  30. # OF THE THEORY OF LIABILITY, EVEN IF IBM OR ITS LICENSORS OR SUPPLIERS
  31. # HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  32. #
  33. # @endCopyright
  34.  
  35. use strict;
  36. use warnings;
  37.  
  38.  open (FILE, 'all.txt');
  39.  my @community; # holds the communities
  40.  my $counter; # number of communities
  41.  while (<FILE>) {
  42.     my @oneline = split("}"); # splits the line into an array of Community entries
  43.     push(@community, @oneline);
  44.  }
  45.  close (FILE);
  46.     $counter = scalar @community;
  47.  
  48.  print "\"name\",\"last modified\",\"owners\",\"parent\"\n"; #headers for CSV
  49.  # iterate through array
  50.  for (my $i = 0; $i < $counter; $i++ ) {
  51.     my @communityParts = split(",", $community[$i]); # the community values are split by comma
  52.     my $communityPartsLen = scalar @communityParts;
  53.     my $name = '';
  54.     my $lastMod = '';
  55.     my $owner = '';
  56.     my $parent = '';
  57.     # iterate through the values, looking for the ones we want
  58.     for (my $j = 0; $j < $communityPartsLen; $j++ ) {
  59.         my $part = $communityParts[$j]; # for convenience
  60.         if ( index($part, "name=") > -1 ) {
  61.             $name = substr $part, index($part,"=") + 1; # just save the name itself
  62.         } elsif ( index($part, "lastMod=") > -1 ) {
  63.             $lastMod = substr $part, index($part,"=") + 1;
  64.         } elsif ( index($part, "OWNER") > -1 ) {
  65.             # might be multiple owners
  66.             my $ownerPart = substr $communityParts[$j - 2], rindex($communityParts[$j - 2],"[") + 1;
  67.             if ( length($owner) > 0 ) {
  68.                 $owner = $owner . " & ";
  69.             }
  70.             $owner = $owner . $ownerPart;
  71.         } elsif ( index($part, "parent") > -1 ) {
  72.             $parent = substr $part, index($part,"=") + 1;
  73.         }
  74.     }
  75.     print "\"$name\",\"$lastMod\",\"$owner\",\"$parent\"\n";
  76.  }
  77.  exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement