免费注册 查看新帖 |

Chinaunix

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

请教sed删除换行符的方法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-30 14:25 |只看该作者 |倒序浏览
我使用sed 's/\n//g' ufile

不行,请大侠赐教!

论坛徽章:
0
2 [报告]
发表于 2009-03-30 14:28 |只看该作者
[test@ ~ ] $ sed ':a;N;s/\n/-_-/g;ta' 1   
a  b,1 c 12-_-a  bb,1 c 12-_-a  1,b,2b  c 12-_-a   1,bb,2b  c 12-_-a   1,bb,2bb  c 12
[test@ ~ ] $ cat 1
a  b,1 c 12
a  bb,1 c 12
a  1,b,2b  c 12
a   1,bb,2b  c 12
a   1,bb,2bb  c 12

论坛徽章:
0
3 [报告]
发表于 2009-03-30 14:29 |只看该作者
原帖由 我是DBA 于 2009-3-30 14:28 发表
[test@ ~ ] $ sed ':a;N;s/\n/-_-/g;ta' 1   
a  b,1 c 12-_-a  bb,1 c 12-_-a  1,b,2b  c 12-_-a   1,bb,2b  c 12-_-a   1,bb,2bb  c 12
[test@ ~ ] $ cat 1
a  b,1 c 12
a  bb,1 c 12
a  1,b,2b  c 12
...



晕怎么那么复杂啊?

论坛徽章:
0
4 [报告]
发表于 2009-03-30 14:32 |只看该作者

回复 #3 linuxboy823 的帖子

我是做个演示给你看.
其实你的方法就是可以的啊.

论坛徽章:
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
5 [报告]
发表于 2009-03-30 14:35 |只看该作者
单行pattern space根本没有\n。还用删除?

论坛徽章:
0
6 [报告]
发表于 2009-03-30 14:38 |只看该作者
gei_1/1 is up,  line protocol is up
  Interface utilization: input      14%,     output       9%

gei_1/2 is down,  line protocol is down
  Interface utilization: input       0%,     output       0%突然

gei_1/3 is up,  line protocol is up
  Interface utilization: input       10%,     output       10%

我就是想把is down /is up和下面一行连接起来,删除空行的我搞定了,去除换行符还没有搞定呢!


不要用tr ,tr我已经会了,呵呵1

论坛徽章:
0
7 [报告]
发表于 2009-03-30 14:40 |只看该作者

回复 #6 linuxboy823 的帖子

sed 'N;s/\n/ /g'  
你这样用就可以

论坛徽章:
9
2015亚冠之阿尔纳斯尔
日期:2015-09-10 16:21:162015亚冠之塔什干火车头
日期:2015-07-01 16:23:022015年亚洲杯之巴勒斯坦
日期:2015-04-20 17:19:46子鼠
日期:2014-11-13 09:51:26未羊
日期:2014-08-28 18:13:36技术图书徽章
日期:2014-02-21 09:30:15酉鸡
日期:2014-01-14 11:12:49天蝎座
日期:2013-12-09 17:56:53平安夜徽章
日期:2015-12-26 00:06:30
8 [报告]
发表于 2009-03-30 14:41 |只看该作者
原帖由 linuxboy823 于 2009-3-30 14:38 发表
gei_1/1 is up,  line protocol is up
  Interface utilization: input      14%,     output       9%

gei_1/2 is down,  line protocol is down
  Interface utilization: input       0%,     output   ...

仔细看2楼的演示

论坛徽章:
0
9 [报告]
发表于 2009-03-30 14:49 |只看该作者
[root@Greendays ~]# awk 'BEGIN{RS=""; FS="\n";ORS="\n\n"}{print NR,$1,$2}' dba
1 gei_1/1 is up,  line protocol is up   Interface utilization: input      14%,     output       9%

2 gei_1/2 is down,  line protocol is down   Interface utilization: input       0%,     output       0%突然

3 gei_1/3 is up,  line protocol is up   Interface utilization: input       10%,     output       10%

[root@Greendays ~]# cat dba
gei_1/1 is up,  line protocol is up
  Interface utilization: input      14%,     output       9%

gei_1/2 is down,  line protocol is down
  Interface utilization: input       0%,     output       0%突然

gei_1/3 is up,  line protocol is up
  Interface utilization: input       10%,     output       10%

论坛徽章:
0
10 [报告]
发表于 2009-03-30 14:53 |只看该作者

回复 #7 我是DBA 的帖子

奇怪了
[linuxboy823@fc8 shell]$ sed ' N; s/\n//g' 13.txt
gei_1/1 is up,  line protocol is up  Interface utilization: input      14%,     output       9%
gei_1/2 is down,  line protocol is down
  Interface utilization: input       0%,     output       0%
gei_1/3 is up,  line protocol is up  Interface utilization: input       10%,     output       10%

第二个换行符就没有被替换掉!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP