Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # @copyright(disclaimer)
- #
- # Licensed Materials - Property of IBM
- # 5724-L31
- # (C) Copyright IBM Corp. 2017. All Rights Reserved.
- #
- # US Government Users Restricted Rights
- # Use, duplication or disclosure restricted by GSA ADP Schedule
- # Contract with IBM Corp.
- #
- # DISCLAIMER OF WARRANTIES :
- #
- # Permission is granted to copy and modify this Sample code, and to
- # distribute modified versions provided that both the copyright
- # notice, and this permission notice and warranty disclaimer appear
- # in all copies and modified versions.
- #
- # THIS SAMPLE CODE IS LICENSED TO YOU "AS-IS".
- # IBM AND ITS SUPPLIERS AND LICENSORS DISCLAIM
- # ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, IN SUCH SAMPLE CODE,
- # INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES
- # OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
- # WILL IBM OR ITS LICENSORS OR SUPPLIERS BE LIABLE FOR ANY DAMAGES ARISING
- # OUT OF THE USE OF OR INABILITY TO USE THE SAMPLE CODE, DISTRIBUTION OF
- # THE SAMPLE CODE, OR COMBINATION OF THE SAMPLE CODE WITH ANY OTHER CODE.
- # IN NO EVENT SHALL IBM OR ITS LICENSORS AND SUPPLIERS BE LIABLE FOR ANY
- # LOST REVENUE, LOST PROFITS OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- # CONSEQUENTIAL,INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS
- # OF THE THEORY OF LIABILITY, EVEN IF IBM OR ITS LICENSORS OR SUPPLIERS
- # HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- #
- # @endCopyright
- use strict;
- use warnings;
- open (FILE, 'all.txt');
- my @community; # holds the communities
- my $counter; # number of communities
- while (<FILE>) {
- my @oneline = split("}"); # splits the line into an array of Community entries
- push(@community, @oneline);
- }
- close (FILE);
- $counter = scalar @community;
- print "\"name\",\"last modified\",\"owners\",\"parent\"\n"; #headers for CSV
- # iterate through array
- for (my $i = 0; $i < $counter; $i++ ) {
- my @communityParts = split(",", $community[$i]); # the community values are split by comma
- my $communityPartsLen = scalar @communityParts;
- my $name = '';
- my $lastMod = '';
- my $owner = '';
- my $parent = '';
- # iterate through the values, looking for the ones we want
- for (my $j = 0; $j < $communityPartsLen; $j++ ) {
- my $part = $communityParts[$j]; # for convenience
- if ( index($part, "name=") > -1 ) {
- $name = substr $part, index($part,"=") + 1; # just save the name itself
- } elsif ( index($part, "lastMod=") > -1 ) {
- $lastMod = substr $part, index($part,"=") + 1;
- } elsif ( index($part, "OWNER") > -1 ) {
- # might be multiple owners
- my $ownerPart = substr $communityParts[$j - 2], rindex($communityParts[$j - 2],"[") + 1;
- if ( length($owner) > 0 ) {
- $owner = $owner . " & ";
- }
- $owner = $owner . $ownerPart;
- } elsif ( index($part, "parent") > -1 ) {
- $parent = substr $part, index($part,"=") + 1;
- }
- }
- print "\"$name\",\"$lastMod\",\"$owner\",\"$parent\"\n";
- }
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement