How can I find the missing integers in a unique and sequential list (one per line) in a unix terminal?
Using awk you can do this:
awk '{for(i=p+1; i<$1; i++) print i} {p=$1}' file
2
6
7
Using seq
and grep
:
seq $(head -n1 file) $(tail -n1 file) | grep -vwFf file -
seq
creates the full sequence, grep
removes the lines that exists in the file from it.