免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1192 | 回复: 2

[文本处理] sed 2合1 [复制链接]

论坛徽章:
6
程序设计版块每日发帖之星
日期:2016-05-11 06:20:00操作系统版块每日发帖之星
日期:2016-05-12 06:20:00每日论坛发贴之星
日期:2016-05-12 06:20:00操作系统版块每日发帖之星
日期:2016-05-14 06:20:00程序设计版块每日发帖之星
日期:2016-05-31 06:20:00每日论坛发贴之星
日期:2016-05-31 06:20:00
发表于 2018-08-18 14:52 |显示全部楼层
# [ /home/soio/1bs/awks ] {2018-08-18 14:43:36}
: 1534574616:0;➜  cat sed.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.

#--#
# [ /home/soio/1bs/awks ] {2018-08-18 14:43:47}
: 1534574627:0;➜  sed '=' sed.N | sed 'N;s/\n/--/'
1--N:
2--Add a newline to the pattern space,
3-- then append the next line of input to the pattern space.
4--If there is no more input then sed exits without processing any more commands.

# [ /home/soio/1bs/awks ] {2018-08-18 14:48:58}
: 1534574938:0;➜  sed '=;{N;s/\n/ /}' sed.N
1
N: Add a newline to the pattern space,
3
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.



# [ /home/soio/1bs/awks ] {2018-08-18 14:48:47}
: 1534574927:0;➜  sed '=;/^[0-9][0-9]*/N;s/\n/ /' sed.N
1
N:
2
Add a newline to the pattern space,
3
then append the next line of input to the pattern space.
4
If there is no more input then sed exits without processing any more commands.

想把她 2合1 失败了

论坛徽章:
20
程序设计版块每日发帖之星
日期:2015-10-11 06:20:0015-16赛季CBA联赛之山东
日期:2016-05-28 18:18:5615-16赛季CBA联赛之新疆
日期:2017-04-12 22:55:4715-16赛季CBA联赛之青岛
日期:2017-06-26 18:30:0315-16赛季CBA联赛之四川
日期:2017-09-04 12:27:0315-16赛季CBA联赛之福建
日期:2018-02-09 14:28:3315-16赛季CBA联赛之同曦
日期:2018-04-17 12:43:3415-16赛季CBA联赛之浙江
日期:2018-07-14 13:27:4015-16赛季CBA联赛之吉林
日期:2018-09-13 15:48:2915-16赛季CBA联赛之新疆
日期:2016-05-07 05:05:3215-16赛季CBA联赛之八一
日期:2016-03-14 12:32:06程序设计版块每日发帖之星
日期:2015-12-12 06:20:00
发表于 2018-08-18 16:10 |显示全部楼层
cat -n /etc/passwd | sed -r 's/^ +//;s/([0-9]+)[^ ]/\1--/'

论坛徽章:
6
程序设计版块每日发帖之星
日期:2016-05-11 06:20:00操作系统版块每日发帖之星
日期:2016-05-12 06:20:00每日论坛发贴之星
日期:2016-05-12 06:20:00操作系统版块每日发帖之星
日期:2016-05-14 06:20:00程序设计版块每日发帖之星
日期:2016-05-31 06:20:00每日论坛发贴之星
日期:2016-05-31 06:20:00
发表于 2018-08-18 17:38 |显示全部楼层
回复 2# baby_神

# [ /home/soio/1bs/awks/ja1 ] {2018-08-18 17:35:36}
: 1534584936:0;➜  sed -r 's/^ +//;s/([0-9]+)[^ ]/\1--/' ../sed.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.

#--#
只是要 sed 模拟 cat | nl 输出 行号 ;1 行的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP