使用sed或awk的cidr转换器 [英] cidr converter using sed or awk

查看:157
本文介绍了使用sed或awk的cidr转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有cidr格式IP地址的文本文件。每行一个cidr。如何将cidrs转换为IP范围,即启动IP - 结束IP。每行一个IP范围。请注意 - 两侧的空格。

I have a text file with IP addresses in cidr format. One cidr per line. How do I convert the cidrs to IP ranges i.e start IP - end IP. One IP range per line. Please note the space on either side of the - .

推荐答案

你最好使用 ipcalc

ipcalc 192.168.0.1/24 -nb | awk '/HostMin/{min=$NF} /HostMax/{max=$NF} END {print min" - "max}'
192.168.0.1 - 192.168.0.254






循环文件的简单脚本:


A simple script to loop through the file:

#!/bin/bash

cat file.txt |\
while IFS= read ip; do
    ipcalc "$ip" -nb |\
    awk '   /HostMin/{min=$NF} 
            /HostMax/{max=$NF} 
            END {print min" - "max}'
done

这篇关于使用sed或awk的cidr转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆