yahui102 2022-01-19 00:42 采纳率: 100%
浏览 23
已结题

求写法,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)

  • 写回答

2条回答 默认 最新

  • _GX_ 2022-01-19 23:56
    关注

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

    $ 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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月30日
  • 已采纳回答 1月22日
  • 修改了问题 1月19日
  • 修改了问题 1月19日
  • 展开全部

悬赏问题

  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题