#!/usr/bin/perl my (%data); $currentGroup = ""; while (<>) { next if /^$/; # filter out groups: if ( /^\[(.+)\]$/ ) { $currentGroup = $1; next; }; # store all keys regarding Identities in the hash: if ( $currentGroup =~ /^Identity/ ) { ($key,$value) = split /=/; chomp $value; $data{$currentGroup}{$key} = $value; } } # We need to prevent this script from being run twice, since it would # kill all identities then. # Non-presence of the [Identity]IdentityList key is the best indiator: unless ( defined( $data{'Identity'}{'IdentityList'} ) ) { exit; } # first, delete all old groups: foreach $group ( keys %data ) { print "# DELETEGROUP [$group]\n"; } # now, extract the list of valid identities (and their sequence): $rawIdentityList = $data{'Identity'}{'IdentityList'}; # don't include the IdentityList anymore: delete $data{'Identity'}{'IdentityList'}; # remove backslash-quoting: $rawIdentityList =~ s/\\(.)/$1/g; # split into a list at unquoted commas: @identities = split /(?