求写法,linux 循环查找缺失id,并保存缺失id到txt文件

如一个有如下规律的文本,通过linux脚本找出缺失的id,并保存到一个文件里.
id_0021
id_0023
id_0024
id_0026
id_0027
以上缺少id_0022 和id_0025
这两个值保存到1.txt中,应该怎么写?

感谢朋友热心回复!
如果是如下例子,应该怎么列出空ip?
Nmap scan report for 192.168.0.1
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.5
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.6
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.7
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.8
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.15
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.16
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.254
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)

对于你的第二个问题,回答如下。

$ cat test.txt
Nmap scan report for 192.168.0.1
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.5
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.6
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.7
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.8
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.15
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.16
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
Nmap scan report for 192.168.0.254
Host is up (0.00017s latency).
MAC Address: A0:42:3F:32:90:00 (Tyan Computer)
$ cat test.txt | grep 192 | awk '{prefix=substr($0,22,10);a[int(substr($0,32))]=1}END{for(i=1;i<255;i++) if(!(i in a)) print prefix""i}'
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.9
192.168.0.10
192.168.0.11
192.168.0.12
192.168.0.13
192.168.0.14
192.168.0.17
192.168.0.18
192.168.0.19
192.168.0.20
192.168.0.21
192.168.0.22
...
192.168.0.253
$ cat test.txt
id_0021
id_0023
id_0024
id_0026
id_0027
$ cat test.awk
BEGIN { min = 9999; max = 0; }
{
    prefix = substr($0, 1, 3);
    id = int(substr($0, 4));
    if (id < min)
        min = id;
    if (id > max)
        max = id;
    a[id] = 1;
}
END {
    for (i=min + 1; i < max; i++)
        if (!(i in a))
            print prefix""sprintf("%04d", i);
}
$ cat test.txt | awk -f test.awk > 1.txt
$ cat 1.txt
id_0022
id_0025