Finding gaps in sequential numbers

With awk :

awk '$1!=p+1{print p+1"-"$1-1}{p=$1}' file.txt

explanations

  • $1 is the first column from current input line
  • p is the previous value of the last line
  • so ($1!=p+1) is a condition : if $1 is different than previous value +1, then :
  • this part is executed : {print p+1 "-" $1-1} : print previous value +1, the - character and fist columns + 1
  • {p=$1} is executed for each lines : p is assigned to the current 1st column

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)