Collapsing a series of comma separated numbers in a sequence to Beginning-End
3
votes
2
answers
421
views
Problem I am trying to solve/enhance a BASH script that provides a number sequence:
I am using a topologically aware tool (lstopo-no-graphics) to extract physical processor numbers to use for input to numactl for processor binding.
Example output for L3 L#4 shared cache physical core
lstopo-no-graphics --no-io|sed -n "/L3 L#3/,/L3/p"|grep -v "L3\|L2"|tr -s '[:space:]'|cut -d " " -f4|grep -o "[0-9]*"|sort -g|tr '\n' ','|sed '$s/,$//'
results in the number series string:
32,33,34,35,36,37,38,39,96,97,98,99,100,101,102,103
All well and good, I use this series for the
numactl --physcpubin=32,33,34,35,36,37,38,39,96,97,98,99,100,101,102,103
، I would would like to be able to collapse the sequence down to numactl --physcpubin=32-39,96-103
, looking to collapse multiple comma separated number sequences to an "a-n" series when sequential, with each sequence comma separated.
I don't have a problem with the existing bash script, just looking for a cleaner implementation if anyone has any ideas?
Asked by Goomba1050
(33 rep)
Apr 27, 2021, 04:26 PM
Last activity: May 8, 2021, 03:23 PM
Last activity: May 8, 2021, 03:23 PM