如何使用vim命令与SED进行括号? - 除非第一个字符发行
我有这个配置文件,我想从中展开它的括号。 据我所知,我可以最好地使用vim -e -c'supper tose''
输入文件
["12000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12000",["127.0.0.1:12000"]]
应该看起来像这样。
所需的输出
[
"12000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12000",
[
"127.0.0.1:12000"
]
]
实际上,这只是第一步,但是我已经使用gg = g
来确定了这些输出。
在VIM本身中测试时使用的此命令:
:%s/^\[/\[\r/|%s/[^^]\[/\r\[\r/g|%s/\]/\r\]/g
以下是我现在可以看到
输出文件
[
"12000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12000"
[
"127.0.0.1:12000"
]
]
的主要问题是我的支架替换sed命令替换了两个字符而不是一个字符。我认为s/[^^] \ [/\ r \ [\ r/g
我代码的一部分是错误的。
它查看两个字符的图案,第一个字符不应是该行的第一个字符,第二个字符应该是开放式括号。
但是,那不是我想要的。我只想查看打开括号,只有在它们不是第一个字符时才替换它们。
我该怎么做?
I've got this config file that I'd like to unfold it's brackets from.
As far as I can tell I can best use the vim -e -c 'stuff goes here'
command for this and put that inside a shell script.
Input file
["12000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12000",["127.0.0.1:12000"]]
It should look like this.
Desired output
[
"12000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12000",
[
"127.0.0.1:12000"
]
]
Well actually, that's just the first step, but I've got those mostly figured out using gg=G
.
This command used when testing in vim itself:
:%s/^\[/\[\r/|%s/[^^]\[/\r\[\r/g|%s/\]/\r\]/g
And below is what I get to see
Output file
[
"12000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12000"
[
"127.0.0.1:12000"
]
]
My main issue right now is that my bracket replacement sed command replaces two characters instead of one. I figured that the s/[^^]\[/\r\[\r/g
part of my code is wrong.
It looks at a pattern of two characters, a first character should not be the first character of the line and a second character should be an opening bracket.
That's however not what I want. I just want to look at opening brackets and only replace them if they are not the first character.
How would I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此
SED
可以工作或
vim
This
sed
may workOr
vim