免费注册 查看新帖 |

Chinaunix

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

[文本处理] 请问怎样实现对文本中每一行特定字符后的数值进行等量的加法运算 [复制链接]

论坛徽章:
1
2015亚冠之首尔
日期:2015-11-03 18:40:52
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-04-13 15:37 |只看该作者 |倒序浏览
原文件如下:
(globals
    version = 3
    io_order = default
)
(iopin
    (bottom
        (pin name="COE"        offset=22.0000 layer=4 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="MOON"        offset=26.0000 layer=4 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="TYPE"        offset=30.0000 layer=4 width=0.2000 depth=0.6000 place_status=fixed  )
)
    (left
        (pin name="AMB"        offset=22.0000 layer=3 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="END"        offset=26.0000 layer=3 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="TOU"        offset=30.0000 layer=3 width=0.2000 depth=0.6000 place_status=fixed  )
)
......
先找到bottom所属的区间,然后将每一行offset=后面的数值均增加100,再找到left所属的区间,然后将每一行offset=后面的数值均增加0.5结果如下:
(globals
    version = 3
    io_order = default
)
(iopin
    (bottom
        (pin name="COE"        offset=122.0000 layer=4 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="MOON"        offset=126.0000 layer=4 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="TYPE"        offset=130.0000 layer=4 width=0.2000 depth=0.6000 place_status=fixed  )
)
    (left
        (pin name="AMB"        offset=22.5000 layer=3 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="END"        offset=26.5000 layer=3 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="TOU"        offset=30.5000 layer=3 width=0.2000 depth=0.6000 place_status=fixed  )
)
......

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
2 [报告]
发表于 2015-04-13 16:21 |只看该作者
回复 1# jiawei2426

$ awk '/^)/{add=0}/^[\t ]*[(](bottom|left)/{add=($1=="(left")?0.5:100}add{if(match($0,"offset=([^ ]+)",a)){sub(a[1],sprintf("%.4f",a[1]+add))}}1' FILE
(globals
    version = 3
    io_order = default
)
(iopin
    (bottom
        (pin name="COE"        offset=122.0000 layer=4 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="MOON"        offset=126.0000 layer=4 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="TYPE"        offset=130.0000 layer=4 width=0.2000 depth=0.6000 place_status=fixed  )
)
    (left
        (pin name="AMB"        offset=22.5000 layer=3 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="END"        offset=26.5000 layer=3 width=0.2000 depth=0.6000 place_status=fixed  )
        (pin name="TOU"        offset=30.5000 layer=3 width=0.2000 depth=0.6000 place_status=fixed  )
)

   

论坛徽章:
1
2015亚冠之首尔
日期:2015-11-03 18:40:52
3 [报告]
发表于 2015-04-13 16:59 |只看该作者
谢谢你的code,验证完全OK,实现了需要的功能.真是太强大了,非常感谢.回复 2# jason680


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP