在 vi 编辑器中使用通配符查找和替换
Find and replace using wildcard in vi editor
我有一个类似于 json 格式的大文本文件。部分文字是这样的:
...
{
"term":
"to_zone" : ["sas"]
"from_zone" : ["sas-inside inside"]
"source" : ["10.100.31.111/32 10.100.31.112/32 10.100.31.113/32 100.100.5.31/32 100.100.5.32/32 100.100.5.33/32"]
"destination": ["100.100.8.129/32 100.100.8.130/32 100.100.8.131/32"]
"source_user" : ["any"]
"category" : ["any"]
"application" : ["any"]
"service" : ["tcp-2181 tcp-10500"]
"source_hip" : ["any"]
"destination_hip" : ["any"]
"tag" : ["sas"]
"action" : ["allow"]
"profile_setting" : ["alert-only"]
},
在 vi 编辑器中是否有任何方法可以扫描 'lists' 并插入引号和逗号来完成元素?
预期结果为:
{
"term":
"to_zone" : ["sas"]
"from_zone" : ["sas-inside inside"]
"source" : ["10.100.31.111/32","10.100.31.112/32","10.100.31.113/32","100.100.5.31/32","100.100.5.32/32","100.100.5.33/32"]
"destination": ["100.100.8.129/32","100.100.8.130/32","100.100.8.131/32"]
"source_user" : ["any"]
"category" : ["any"]
"application" : ["any"]
"service" : ["tcp-2181","tcp-10500"]
"source_hip" : ["any"]
"destination_hip" : ["any"]
"tag" : ["sas"]
"action" : ["allow"]
"profile_setting" : ["alert-only"]
},
我不知道 vi 编辑器中的查找和替换功能中的正则表达式如何。请注意,列表的开头和结尾都有现有的引号,因此使其成为单元素字符串,list.
vi 具有搜索和替换功能。您将不得不 运行 多次执行此操作,直到它再也找不到该模式,但这应该可以做到。
:%s/\(\[".\{-\}\) /","/g
我有一个类似于 json 格式的大文本文件。部分文字是这样的:
...
{
"term":
"to_zone" : ["sas"]
"from_zone" : ["sas-inside inside"]
"source" : ["10.100.31.111/32 10.100.31.112/32 10.100.31.113/32 100.100.5.31/32 100.100.5.32/32 100.100.5.33/32"]
"destination": ["100.100.8.129/32 100.100.8.130/32 100.100.8.131/32"]
"source_user" : ["any"]
"category" : ["any"]
"application" : ["any"]
"service" : ["tcp-2181 tcp-10500"]
"source_hip" : ["any"]
"destination_hip" : ["any"]
"tag" : ["sas"]
"action" : ["allow"]
"profile_setting" : ["alert-only"]
},
在 vi 编辑器中是否有任何方法可以扫描 'lists' 并插入引号和逗号来完成元素?
预期结果为:
{
"term":
"to_zone" : ["sas"]
"from_zone" : ["sas-inside inside"]
"source" : ["10.100.31.111/32","10.100.31.112/32","10.100.31.113/32","100.100.5.31/32","100.100.5.32/32","100.100.5.33/32"]
"destination": ["100.100.8.129/32","100.100.8.130/32","100.100.8.131/32"]
"source_user" : ["any"]
"category" : ["any"]
"application" : ["any"]
"service" : ["tcp-2181","tcp-10500"]
"source_hip" : ["any"]
"destination_hip" : ["any"]
"tag" : ["sas"]
"action" : ["allow"]
"profile_setting" : ["alert-only"]
},
我不知道 vi 编辑器中的查找和替换功能中的正则表达式如何。请注意,列表的开头和结尾都有现有的引号,因此使其成为单元素字符串,list.
vi 具有搜索和替换功能。您将不得不 运行 多次执行此操作,直到它再也找不到该模式,但这应该可以做到。
:%s/\(\[".\{-\}\) /","/g