免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: linuxboy823
打印 上一主题 下一主题

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

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

回复 #10 linuxboy823 的帖子

你的是三行并为一行,比较特殊,要多加一个N;
[test@ ~ ] $ sed 'N;N;s/\n/-_-/' 1
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
12 [报告]
发表于 2009-03-30 15:35 |只看该作者

回复 #11 我是DBA 的帖子

N的具体意思是什么啊
`N'
     Add a newline to the pattern space, then append the next line of
     input to the pattern space.  If there is no more input then `sed'
     exits without processing any more commands

没有理解!

论坛徽章:
0
13 [报告]
发表于 2009-03-30 17:24 |只看该作者

回复 #12 linuxboy823 的帖子

N的意思就是把下一行追加到当前行尾

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

回复 #1 linuxboy823 的帖子

仔细看看man sed,看看sed是怎样读文件的

论坛徽章:
0
15 [报告]
发表于 2009-03-30 21:09 |只看该作者
我想“我是DBA”这小子今天不是在泡妞就是给妞泡晕了
再不就是给人盗号了,完全不像他的风格

  1. $ cat >aa
  2. gei_1/1 is up,  line protocol is up
  3.   Interface utilization: input      14%,     output       9%

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

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

  8. Administrator@ad85992220194fe ~
  9. $ sed '/is down\|is up/{N;s/\n//}' aa
  10. gei_1/1 is up,  line protocol is up  Interface utilization: input      14%,
  11. output       9%

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

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

  16. Administrator@ad85992220194fe ~
复制代码

论坛徽章:
0
16 [报告]
发表于 2009-03-31 10:01 |只看该作者

回复 #13 我是DBA 的帖子

那又为什么要用2个N才能实现呢?

论坛徽章:
0
17 [报告]
发表于 2009-03-31 10:04 |只看该作者

回复 #16 linuxboy823 的帖子

两个N就把下面两行都搞上来。

论坛徽章:
0
18 [报告]
发表于 2009-05-14 14:30 |只看该作者
sed -e :a -e 'N;s/\n//;ta'


: label
              Label for b and t commands.


Commands which accept address ranges
       {      Begin a block of commands (end with a }).

       b label
              Branch to label; if label is omitted, branch to end of script.

       t label
              If a s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to    end of script.

       T label
              If no s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is  omitted,  branch    to end of script.

[ 本帖最后由 gqkkk 于 2009-5-14 14:37 编辑 ]

论坛徽章:
0
19 [报告]
发表于 2009-05-14 16:02 |只看该作者

回复 #11 我是DBA 的帖子

[root@Greendays lianshou]# cat b
1
2
3
4
5
6
7
8
9
0
[root@Greendays lianshou]# sed 'N;N;s/\n/\t/' b
1       2
3
4       5
6
7       8
9
0
这是怎么回事?你的bash 是那个版本的?

论坛徽章:
14
处女座
日期:2013-11-26 09:21:15操作系统版块每日发帖之星
日期:2016-03-25 06:20:00操作系统版块每日发帖之星
日期:2016-03-22 06:20:00操作系统版块每日发帖之星
日期:2016-03-21 06:20:00数据库技术版块每日发帖之星
日期:2015-11-13 06:20:00操作系统版块每日发帖之星
日期:2015-11-01 06:20:002015亚冠之卡尔希纳萨夫
日期:2015-09-29 13:31:42IT运维版块每日发帖之星
日期:2015-08-13 06:20:00IT运维版块每日发帖之星
日期:2015-08-10 06:20:00数据库技术版块每日发帖之星
日期:2015-08-06 06:20:00双鱼座
日期:2014-07-17 15:08:51卯兔
日期:2014-04-08 09:54:34
20 [报告]
发表于 2012-04-20 09:46 |只看该作者
  1. tr -d '\n'
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP