The voodoo would be to use perl. There is a Perl modules for reading and
wring Asterisk config files. You'll have to google for it.

Here is a perl script I just wrote that does what you want. Be aware
that I just wrote it so it has had exactly 2 seconds of testing. Use at
your own risk. However, that being said, this does not effect your
original file. The results are simply sent to STDOUT so you can pipe
them to another file.

ALso, be warned that it strips all comments.

----


#!/usr/bin/perl
use strict;

my %sippeers;
my $sipfile = $ARGV[0];
# read in existing voicemail PINs
open(PINFILE, "<  $sipfile") || die("can't open $sipfile: $!");
my $context;
my $flag = 0;
while (<PINFILE>) {
        if (m/^;/) { next; } # skip comments
        if (m/^\[([0-9a-zA-Z]+)\]/) { # scan the file for the start of a context
                $context = $1;
                $flag = 1;
        } elsif($flag == 1) {
                $sippeers{$context} .= $_;
        } else {
                print("$_\n");
        }
}
close PINFILE;
print("[general]\n");
print($sippeers{'general'});
delete $sippeers{'general'};
for my $sippeer (sort { $a cmp $b } keys %sippeers) {
        print("[$sippeer]\n");
        print($sippeers{$sippeer});
}

----

-- 
John Lange
www.johnlange.ca


On Mon, 2008-04-28 at 08:45 -0400, Chad Osmond wrote:
> Hey, 
> 
> Does anyone have some kung-foo for sorting the contents of say sip.conf of 
> extensions.conf?
> 
> It's a little too complex for awk | sort, so I thought maybe someone has some 
> perl floating around that'll do it.
> 
> Chad
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to