3 # Looks for phone numbers in your .bbdb with a particular area code
4 # and one of a set of exchanges and changes the area code. The old
5 # and new area codes are specified on the command line, as is the
6 # location of a file that contains the exchanges that are being
7 # changed. (The format of that file is very loose. Every three digit
8 # sequence will be used.)
10 # Seth Golub <seth@cs.wustl.edu>
16 die "Usage: \n $0 <old-code> <new-code> <exchanges-file> [bbdb]\n";
19 $old_area_code = shift || Usage();
20 $new_area_code = shift || Usage();
21 $exchange_list_file = shift || Usage();
23 $bbdb_file = $ENV{'BBDB'} || shift || $ENV{'HOME'} . '/.bbdb';
24 $bbdb_dir = `dirname $bbdb_file`; chomp $bbdb_dir;
25 $tmp_file = "$bbdb_dir/bbdb.new-$$";
27 open( LIST, "<$exchange_list_file" )
28 || die "Failed to open $exchange_list_file\n";
34 push( @exchanges, $1 );
40 $exchanges = join( '|', @exchanges );
42 open( BBDB_IN, "<$bbdb_file" ) || die "Failed to open $bbdb_file\n";
43 open( BBDB_OUT, ">$tmp_file" ) || die "Failed to open $tmp_file\n";
48 s/(\[\".*?\") $old_area_code (($exchanges) \d+ \d+\])/$1 $new_area_code $2/og;
56 unlink( "$bbdb_file.bak" );
57 rename( $bbdb_file, "$bbdb_file.bak" );
58 rename( $tmp_file, $bbdb_file );
60 print STDERR "Old bbdb moved to $bbdb_file.bak\n";