更改号码格式
我有很多行包含 XXXXXXXXX-XXX.XXX
数字格式。我想将号码 XXXXXXXXX-XXX.XXX
更改为 XX.XXX.XXX.X-XXX.XXX
XXXXXXXXX-XXX.XXX
= 15 位数字随机数
谁能帮我?提前致谢
I have a lot lines contains XXXXXXXXX-XXX.XXX
number format. I want change number XXXXXXXXX-XXX.XXX
to XX.XXX.XXX.X-XXX.XXX
XXXXXXXXX-XXX.XXX
= 15 digit random number
Anyone can help me? Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
常规正则表达式:搜索
(\d{2})(\d{3})(\d{3})(\d)-(\d{3}\.\d{3}) 并替换为
\1.\2.\3.\4-\5
。我不太了解 sed,但我认为语法有点不同。试试这个:
General regex: Search for
(\d{2})(\d{3})(\d{3})(\d)-(\d{3}\.\d{3})
and replace with\1.\2.\3.\4-\5
.I don't know sed well enough, but I think the syntax there is a bit different. Try this:
这很丑陋(因为 sed 使用 POSIX 正则表达式) ,但应该有效:
This is ugly (because sed uses POSIX regex), but should work:
试试这个:(
这输出98.765.432.1)
然后,从文件读取输入:
并且,写入新文件:
我想你可以改进它,但这是一般的想法。
Try this:
(this outputs 98.765.432.1)
Then, for reading input from a file:
and, for writing to a new file:
I guess you could refine it, but that's the general idea.