【发布时间】:2018-07-26 02:33:42
【问题描述】:
假设我有类似 sn-p 的代码:
if(some condition)
{
some code here;
}
else if (some other condition)
{
some more code;
}
public static some_method(something passed here maybe)
{
some other code;
}
然后它应该被格式化为:
if(some condition) {
some code here;
} else if (some other condition) {
some more code;
}
public static some_method(something passed here maybe) {
some other code;
}
这只是示例代码。我想为包含“if 语句、for 循环、方法等”的整个文件运行 sed 脚本。可能相似或格式不同。因此,脚本的主要目的应该是将这些打开的花括号移动一行。提前谢谢..
【问题讨论】:
-
我的建议是不要自己实现这个,而是使用现有的美化工具来编写你正在编写的语言。
-
@TomFenech - 我尊重你的建议,但那些美化/美化工具仅适用于 2-3 个文件。如果您有成百上千的文件,您不能继续浪费一整天的时间来逐个浏览文件,那就是如果我们有一些脚本,那么我们可以循环遍历该脚本并一次尝试处理所有文件。
-
如果您下载的任何工具不支持每次调用美化多个文件,我会感到非常惊讶,如果支持,那么您始终可以编写一个简单的
for循环或使用 @987654324 @ 在 shell 中。
标签: regex shell awk sed powershell-2.0