Показать варианты монтажа смонтированного btrfs?

Решение awk:

awk '{if(p+1==$1){c+=1}else{ if(c>1){printf "%s-%s %s\n", b, p, s;} c=0;s=""}} c==1{b=p} {p=$1;s=s$2}' file

На этот раз немного читабельнее с пояснениями:

awk '{ 
  if(p+1==$1){
    c+=1 # increment the counter if the value is consecutive
  } else {
    if(c>1){
      # print the begin and end values with the concatenated string
      printf "%s-%s %s\n", b, p, s;
    }
    c=0 # reset the counter
    s="" # reset the string to print
  }
}
c==1{b=p} # set the begin value
{p=$1;s=s$2} # set the previous variable and the string for the next loop
' file 

Протестировано с помощью GNU awkиmawk

0
24.07.2021, 05:28
0 ответов

Теги

Похожие вопросы