Php sip.conf配置文件-向每条记录添加新行

Php sip.conf配置文件-向每条记录添加新行,php,python,ruby,regex,linux,Php,Python,Ruby,Regex,Linux,我有一个sip配置文件,如下所示: [1664] username=1664 mailbox=1664@8360 host=192.168.254.3 type=friend subscribemwi=no [1679] username=1679 mailbox=1679@8360 host=192.168.254.3 type=friend subscribemwi=no [1700] username=1700 mailbox=1700@8360 host=192.168.254.3 ty

我有一个sip配置文件,如下所示:

[1664]
username=1664
mailbox=1664@8360
host=192.168.254.3
type=friend
subscribemwi=no
[1679]
username=1679
mailbox=1679@8360
host=192.168.254.3
type=friend
subscribemwi=no
[1700]
username=1700
mailbox=1700@8360
host=192.168.254.3
type=friend
subscribemwi=no
[1701]
username=1701
mailbox=1701@8360
host=192.168.254.3
type=friend
subscribemwi=no
对于每条记录,我需要为每条记录添加另一行(vmxten),例如,上面变成:

[1664]
username=1664
mailbox=1664@8360
host=192.168.254.3
type=friend
subscribemwi=no
vmexten=1664
[1679]
username=1679
mailbox=1679@8360
host=192.168.254.3
type=friend
subscribemwi=no
vmexten=1679
[1700]
username=1700
mailbox=1700@8360
host=192.168.254.3
type=friend
subscribemwi=no
vmexten=1700
[1701]
username=1701
mailbox=1701@8360
host=192.168.254.3
type=friend
subscribemwi=no
vmexten=1701
你认为最快的方法是什么?文件中有数百条记录,因此手动修改所有记录需要很长时间

你会用正则表达式吗?你会用sed吗?我很想知道你将如何处理这个问题


谢谢

只需匹配
^\[(\d+)\]
并替换为
[\1]\r\nvmexten=\1
。不确定python/ruby是否使用
\1
$1
。但是我相信你会明白的。

替换
(\[(\d+)[^\[]+)
with
\1vmexten=\2\n
在我的文本编辑器中工作

请注意,这会产生与OP要求的输出稍有不同的输出,
vmexten
位于节的顶部,而不是底部。虽然这不重要。@Eric:正确,但这是绝对最好的方法,我真的认为不会这很重要。