Page 1 of 1

Simple script to check missing lines

Posted: Wed Jan 11, 2017 7:42 pm
by cah
This script is to find the missing lines in a file with consecutive numbers.
For example:

Code: Select all

1
2
3
5
6
7
9
10
12
15
16
17
22
25
30
The following script will write the following to the missing_line file:

Code: Select all

4
8
11
13
14
18
19
20
21
23
24
26
27
28
29

Code: Select all

#!/bin/ksh

typeset -i i j count row
>missing_line

j=0
count=0

/bin/cat Test.txt | while read i
do
  (( count = ($count + 1) ))
  (( row = ($count + $j) ))
  while [ $row -lt $i ]
  do
    echo $row >> missing_line
    (( row = ($row + 1) ))
    (( j = ($j + 1) ))
  done
done