免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2599 | 回复: 11
打印 上一主题 下一主题

reformat source files [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-13 05:48 |只看该作者 |倒序浏览
As you see, the following line
//ex-compile.c #include <glib.h> int main(int argc, char** argv) { GList* list = NULL; list = g_list_append(list, "Hello world!"); printf("The first item is '%s'\n", g_list_first(list)->data); return 0; }

exists in a text file. I open it in vi and setup 'set list' to see, above line  from the beginning of the line //ex-compile.c  up to return 0; }  seems in ONE line
in the text file.

I wonder How can I reformat the file into normal form as below
//ex-compile.c
#include<glib.h>
int main(int argc, char** argv) {
GList* list=NULL;
...
...
return 0;
}

Thanks in advance.

论坛徽章:
0
2 [报告]
发表于 2009-03-13 06:51 |只看该作者
这个一行变多行,太难了,没规律。。
tim或许有办法。

论坛徽章:
0
3 [报告]
发表于 2009-03-13 07:36 |只看该作者
这个太没规律了,不好办

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
4 [报告]
发表于 2009-03-13 09:15 |只看该作者

回复 #1 mjus 的帖子

try:

sed 's/#include *<[^>]*>/\n&\n/;s/[{;]/&\n/g' urfile

论坛徽章:
0
5 [报告]
发表于 2009-03-13 09:21 |只看该作者

回复 #4 ly5066113 的帖子

太强大了。。
前面两行单独处理
后面碰到{ 分号加换行符。。

论坛徽章:
0
6 [报告]
发表于 2009-03-13 09:33 |只看该作者
还有个问题,就是如果格式正常,他会添加很多空行

[ 本帖最后由 gLandesprung 于 2009-3-13 09:40 编辑 ]

论坛徽章:
1
寅虎
日期:2014-11-30 21:25:54
7 [报告]
发表于 2009-03-13 09:35 |只看该作者

回复 #4 ly5066113 的帖子

看Tim大哥发脚本就是舒服

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
8 [报告]
发表于 2009-03-13 10:45 |只看该作者

回复 #1 mjus 的帖子

vide indent

论坛徽章:
0
9 [报告]
发表于 2009-03-13 11:39 |只看该作者

回复 #8 blackold 的帖子

黑哥,这是什么?编码工具吗?

论坛徽章:
0
10 [报告]
发表于 2009-03-13 23:41 |只看该作者
WOW! Grand Master Tim, your solution is perfect. I'm more than satisfacory about it. Thank you so much !!!

Regards,

BTW, Due to my limited knowledge, Mr. Blackold, what is vide indent ? is it useful in solving my problem ?
could you kindly introduce it to us in more details. thanks a lot.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP