免费注册 查看新帖 |

Chinaunix

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

快,求快,一替换脚注 [复制链接]

论坛徽章:
0
发表于 2009-12-13 04:14 |显示全部楼层
文本内容:
83342543        {"aa.bb.cc":"nihewohetaDiscount$2","close.arrive":"true","stay.max":"2"}
83342544        {"aa.bb.cc":"nihewohetaExtended$2","close.arrive":"false","stay.max":"2"}
83342545        {"aa.bb.cc":"nihewohetaExtended$2","close.arrive":"true","stay.max":"2"}
83342546        {"aa.bb.cc":"nihewohetaBreakfast$2","close.arrive":"false","stay.max":"2"}
83342547        {"aa.bb.cc":"nihewohetaBreakfast$2","close.arrive":"true","stay.max":"2"}
83342548        {"aa.bb.cc":"nihewohetaFlexible$1","close.arrive":"false","stay.max":"1"}
83342549        {"aa.bb.cc":"nihewohetaAdvance$1","close.arrive":"false","stay.max":"1"}
83342550        {"aa.bb.cc":"nihewohetaDiscount$1","stay.max":"1","close.arrive":"false"}
83342551        {"aa.bb.cc":"nihewohetaExtended$1","close.arrive":"false","stay.max":"1"}
83342552        {"aa.bb.cc":"nihewohetaBreakfast$1","close.arrive":"false","stay.max":"1"}     

空的地方是tab

需替换成,比如
83342552        {"aa.bb.cc":"nihewohetaBreakfast$1","close.arrive":"false","stay.max":"1"}  

83342552        {"aa.bb.cc":"nihewohetaBreakfast$1","close.arrive":"false","stay.max":"1","stay.min":"1"}

规则: 1: stay.max后跟数字每行不确定,但一定是数字, 要求stay.min后面跟的和stay.max后面跟的一样
        2: 另外,stay.max在综括号中的,顺序不固定,但一定在综括号中

求执行快的脚本,谢谢. 因为记录上千万级别


不知道还有没高人夜猫子

论坛徽章:
0
发表于 2009-12-13 06:10 |显示全部楼层
这是我自己写的,不过很慢
sed -i 's/stay.max":"\([0-9]\)"/stay.max":"\1","stay.min":"\1"/g' file

为什么是千万的,唉,我得花时间用各种方法测测,只要你想到方法的,麻烦都贴出来,我负责来测

论坛徽章:
0
发表于 2009-12-13 08:20 |显示全部楼层

回复 #1 justinyun 的帖子

sed -r 's/"stay.max(":"[0-9]")/&"stay.min\1/g'

论坛徽章:
0
发表于 2009-12-14 10:02 |显示全部楼层
{code}
sed 's|"stay.max":"\([0-9]\+\)"|&,"stay.min":\1|'
{\code}

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
发表于 2009-12-14 10:09 |显示全部楼层

回复 #4 luyi1983 的帖子

要把花括号替换成方括号

论坛徽章:
0
发表于 2009-12-14 10:28 |显示全部楼层
如果速度慢,试试管道文件,不要用sed -i。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP