变化括号现在的位置与SED [英] change braces postion with sed

查看:140
本文介绍了变化括号现在的位置与SED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个来源$ C ​​$ CS中括号都是这样

I have multiple source codes in which braces are like this

function()
{
    if(...)
    {
        ...
    }
    else
    {
        ...
    }
}

我想使它看起来像这样:

I would like to make it look like this:

function() {
    if(...) {
        ...
    }
    else {
        ...
    }
}

我已经尝试了一些技巧与 SED 命令,但我无法弄清楚如何得到它的正常工作。这里是我的最新尝试:

I've tried some tricks with the sed command, but I can't figure out how to get it working properly. Here is my latest try:

sed ":a; N; $!ba; s/\n{/ {/g" myfile

感谢您的帮助!

编辑 -

我设法把这个工作与命令:

I managed to have this working with that command:

sed "N;/\n *{/s// {/;P;D"

像往常一样与 SED ,我十分不明白为什么它的工作原理,但它确实。

As usual with sed, I quite don't understand why it works, but it does.

推荐答案

既然你执行code格式,我可以建议您使用工具较侧重这一点,并调查类似的的astyle 。以下是为您的具体问题(括号定位)的信息

Since you're performing code formatting, can I suggest you use a tool more geared to this, and investigate something like AStyle. Here's the info for your specific issue (brace positioning)

这篇关于变化括号现在的位置与SED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆