1

How do I findout missing number from two sequence using bash script

from example I have file which contain following data

1 1
1 2
1 3
1 5
2 1
2 3
2 5

output : missing numbers are

1 4
2 2
2 4
user000001
  • 32,226
  • 12
  • 81
  • 108
Rupesh
  • 1,636
  • 13
  • 18
  • If the sequence starts with `1 2` do you consider `1 1` is missing? or if it starts with `2 1` ? – a5hk Apr 28 '14 at 06:07

2 Answers2

3

This awk one-liner gives the requested output for the specified input:

$ awk '$2!=l2+1&&$1==l1{for(i=l2+1;i<$2;i++)print l1,i}{l1=$1;l2=$2}' file
1 4
2 2
2 4
user000001
  • 32,226
  • 12
  • 81
  • 108
2

a solution using grep:

printf "%s\n" {1..2}" "{1..5} | grep -vf file
Farvardin
  • 5,336
  • 5
  • 33
  • 54