CIDR string replacement

The recent thread on CIDR aggregation cleanup scripts reminds me that I’m looking for a similarly efficient implementation of a related tool. (I’m gearing up to write my own in Perl, but don’t want to reinvent the wheel.)

I’d like a fast, Unix-pipeline-ready tool that replaces all IPs within that range with a supplied string, using a simple config file as input, and ideally with autodetection of IP-address “word” boundaries, as in:

$ cat cidr-replace.cfg|[Unitel]|[ACS]|[GCI]|[TEST-NET-1]|[TEST-NET-2]|[TEST-NET-3]

$ echo “source,data1,data2,,data3” | cidr-replace cidr-replace.cfg

And I know this is kludgy, but it would also be useful for quick-and-dirty work if it had a flag to “append” the string using a known delimiter, as in:

$ echo “source,data1,data2,,data3” | cidr-replace --append ‘,’ cidr-replace.cfg

(But I’m happy to hack that last functionality into an existing script.)

This is what I have done using R:

I still use similar tools in Perl with Net::Netmask