Bash Script To Change Figure Style

I have a CSS file and a PHP file that I received from a foreign outsourcing partner. He prefers curly braces on the new line, while I am pretty old school and prefer curly braces on the same line as the declaration. How can I use Bash and / or sed or other command line tools to undo curly braces from this new style and to this older style?

EDIT . Someone wanted to see an example. Ok, here goes:

NEW SCHOOL STYLE I DO NOT LIKE

body 
{
padding:4px;
margin:3px;
}

HIGH 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
}
+3
source share
2 answers
 sed 'N;/\n{/s// {/;P;D' file.css

Enter

$ cat file.css
body
{
background-color:#d0e4fe;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}

Output

$ 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;
}
+3

:

sed 'N;/\n{/s/\n/ /;P;D' inputfile

, ​​ ( ).

0

Source: https://habr.com/ru/post/1781889/


All Articles