With perl, you can use the Set::IntSpan to compress a number sequence.
The solution below can handle mixed and unordered site lists.
input_file
web3.maxi.com web4.maxi.com web5.maxi.com mail1.mexi.com web6.maxi.com web9.maxi.com web9.maxi.com web11.maxi.com mail3.mexi.com web7.maxi.com mail4.mexi.com mail25.mexi.com mail26.mexi.com mail27.mexi.com mail28.mexi.com web8.maxi.com mail29.mexi.com mail110.mexi.com web1.maxi.com
parse.pl
Run it as follows:
perl parse.pl < infile
Output:
web[1,3-9,11].maxi.com mail[1,3-4,25-29,110].mexi.com
Perhaps cryptic @numbers = $nums =~ /$pre(\d+)$post/g expands to an array of elements matching the regular expression and stores it in @numbers .
Note that this solution loads the entire file into memory.
Thor
source share