#!/usr/bin/perl use warnings; use strict; my $file; my %hash = (); my $key = ''; my %kon = (); my @kontrolle = (); my $count = 0; while ( defined ( my $line = ) ) { chomp ( $line ); if ( $line =~ /^\s*#/ || $line =~ /^\s*$/ ) { next; } elsif ( $line =~ /^\s*Datei\s*=\s*'(.*)'/ ) { if ( $file ) { write_to_file ( $file ); %hash = (); } $file = $1; if ( ! -f $file ) { open ( my $fh_w, '>>', $file ) or die "$file $!"; close ( $fh_w ); } open ( my $fh, '<', $file ) or die "$file $!"; while ( <$fh> ) { chomp; next if $_ =~ /^\s*#/ || $_ =~ /^\s*$/; if ( /^\s*\[([^\]]+)\]/ ) { $key = $1; next; } my ( $k, $v ) = split /\s*=\s*/; ${$hash{$key}}{$k} = $v; } close ( $fh ); } else { if ( $line =~ /^\s*\[([^\]]+)\]/ ) { $key = $1; next; } my ( $k, $v ) = split /\s*=\s*/, $line; ${$hash{$key}}{$k} = $v; $kon{$k}++; } } write_to_file ( $file ); sub write_to_file { my $file = shift; open ( my $fh_write, '>', $file ) or die "$file $!"; foreach my $key ( sort keys %hash ) { print $fh_write "[$key]\n"; foreach my $k ( sort keys %{$hash{$key}} ) { foreach ( keys %kon ) { push ( @kontrolle, [ $file, $key, $k, ${$hash{$key}}{$k} ] ) if $_ eq $k; } print $fh_write $k, "=", ${$hash{$key}}{$k}, "\n"; } } close ( $fh_write ); } my $dat = '0'; foreach ( sort { $a->[0] cmp $b->[0] || $a->[2] cmp $b->[2] } @kontrolle ) { print "\n" if $dat ne $_->[0]; print "$_->[0]\t: $_->[2]=$_->[3] [$_->[1]] \n"; $dat = $_->[0]; } __DATA__ Datei = '/home/manfred/.kde/share/config/kdesktoprc' [FMSettings] ShowFileTips=false [ScreenSaver] Enabled=false Datei = '/home/manfred/.kde/share/config/konquerorrc' [FMSettings] ShowFileTips=false [Trash] ConfirmTrash=false