gpt4 book ai didi

regex - + 正则表达式在 sed 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 10:09:36 25 4
gpt4 key购买 nike

团队,

我有一个包含以下数据的文件。

[root@ip-12-32-8-15 ~]# cat dbbackup

(555)555-1212

(555)555-1213

预期输出:

First: (555) Second: 555- Third: 1212

First: (555) Second: 555- Third: 1213

我正在使用 sed,它不工作。

sed -n -e 's/\([0-9]+)\)\([0-9]+-\)\([0-9]+\)/First: \1 Second: \2 Third: \3/p' dbbackup

请告诉我如何实现上述输出。

最佳答案

在 GNU awk (FIELDWIDTHS) 中,没有正则表达式:

$ awk 'BEGIN{FIELDWIDTHS="5 4 4"}{print "First:",$1,"Second:",$2,"Third:",$3}' file
First: (555) Second: 555- Third: 1212
First: (555) Second: 555- Third: 1213

sed 中的另一个:

$ sed 's/^/First: /1;s/./& Second: /12;s/./& Third: /25' file
First: (555) Second: 555- Third: 1212
First: (555) Second: 555- Third: 1213

关于regex - + 正则表达式在 sed 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49913293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com