Мне нужно сгруппировать данные CSV таким образом, чтобы несортированные последовательные IP-адреса с одинаковыми данными порта (столбец G) были объединены в диапазон.
sort --field-separator=',' -k 7 -k 6 $filename.tmp1 > $filename.tmp2 #sort list by port then IP address
awk -F, 'BEGIN {SUBSEP=OFS=FS} ???' $filename.tmp2 > $filename.tmp3 # combine consecutive IPs into ranges
Введите:
"A","B","C","D","E","10.184.110.34","10110 36111"
"A","B","C","D","E","10.184.110.33","1000"
"A","B","C","D","E","10.184.110.36","10110 36111"
"A","B","C","D","E","10.184.110.35","10110 36111"
"A","B","C","D","E","10.184.110.38","10110"
"A","B","C","D","E","10.184.110.39","10110 36111"
"A","B","C","D","E","10.184.110.37","10110"
"A","B","C","D","E","10.184.110.40","10110 36111"
"A","B","C","D","E","10.184.110.42","10110 36111"
Ожидаемый результат:
"A","B","C","D","E","10.184.110.33","1000"
"A","B","C","D","E","10.184.110.34-10.184.110.36","10110 36111"
"A","B","C","D","E","10.184.110.37-10.184.110.38","10110"
"A","B","C","D","E","10.184.110.39-10.184.110.40","10110 36111"
"A","B","C","D","E","10.184.110.42","10110 36111"