变化括号现在的位置与SED

编程入门 行业动态 更新时间:2024-10-18 21:20:42
本文介绍了变化括号现在的位置与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

本文发布于:2023-11-22 14:47:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:括号   位置   SED

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!