[英]Bash Script To Change Curly Brace Style
I have a CSS file and a PHP file that I received from an overseas outsource partner. 我有一个CSS文件和一个PHP文件,我从一个海外外包合作伙伴收到。 He prefers curly braces on a new line, while I am rather Old School and prefer the curly brace on the same line as the declaration.
他喜欢在一条新线上使用花括号,而我更喜欢Old School,并且更喜欢与宣言相同的花括号。 How can I use Bash and/or sed or other command-line tools to revert curly braces from this new style and into this older style?
我如何使用Bash和/或sed或其他命令行工具将这种新样式的花括号恢复到这种旧样式?
EDIT : Someone wanted to see an example. 编辑 :有人想看一个例子。 Okay, here goes:
好的,这里是:
NEW SCHOOL STYLE I DO NOT LIKE 新学校风格我不喜欢
body
{
padding:4px;
margin:3px;
}
OLD SCHOOL I PREFER 老学校我喜欢
body {
padding:4px;
margin:3px;
}
NEW SCHOOL STYLE I DO NOT LIKE 新学校风格我不喜欢
function foo()
{
// some code here
}
OLD SCHOOL STYLE I PREFER 老学校风格我喜欢
function foo() {
// some code here
}
sed 'N;/\n{/s// {/;P;D' file.css
$ cat file.css
body
{
background-color:#d0e4fe;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
$ sed 'N;/\n{/s// {/;P;D' file.css
body {
background-color:#d0e4fe;
}
h1 {
color:orange;
text-align:center;
}
p {
font-family:"Times New Roman";
font-size:20px;
}
A start might be: 一个开始可能是:
sed 'N;/\n{/s/\n/ /;P;D' inputfile
If a line begins with a curly brace, it will be appended to the previous line (with an added space). 如果一行以大括号开头,则会将其附加到上一行(添加空格)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.