Simple script to check missing lines

Moderator: cah

Post Reply
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1342
Joined: Sun Aug 17, 2008 5:05 am

Simple script to check missing lines

Post 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
CAH, The Great
Post Reply