将文件中的所有 IP 地址替换为指定的字符串 [英] Replace all IP addresses in a file to a specified string

查看:19
本文介绍了将文件中的所有 IP 地址替换为指定的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文件中有一个很大的 IP 地址 列表,我想将所有 IP 地址替换为指定的字符串(示例:X.X.X.X).

I have a huge list of IP address in a file and I want to replace all the IP address to a specified string( Example : X.X.X.X).

#Example.txt
1,1.1.1.1
2,10.10.10.10
3,5.5.5.5
4,6.6.6.6
.........

我尝试使用 sed

$sed -e 's/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/x.x.x.x/g' example.txt

我无法做到这一点.有人可以帮助我如何用特定字符串替换 IP 地址吗?

I couldn't achieve this. Can some one help me on how to replace the IP address with a specific string?

推荐答案

您就快到了!您所要做的就是避开重复大括号:

You were almost there! All that you have to do is escape the repetition braces:

sed -e 's/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/x.x.x.x/g' test.txt

这篇关于将文件中的所有 IP 地址替换为指定的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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