免费注册 查看新帖 |

Chinaunix

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

[文本处理] 求助:若第2列包含ep4a或ep4 ,则在最后一列显示1/1-4 [复制链接]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-05-22 19:38 |只看该作者 |倒序浏览
本帖最后由 itpark 于 2014-05-22 19:38 编辑

请问下面的脚本,如何在最后一列加上这样的内容

若第2列包含ep4a或ep4 ,则在最后一列 加上Slot ID 列所显示的数字+1-4, (比如1/1-4)
若第2列包含ep16 ,则在最后一列 加上Slot ID 列所显示的数字+1-16, (比如2/1-16)
若第2列包含2pon ,则在最后一列 加上Slot ID 列所显示的数字+1-2, (比如9/1-2)


谢谢

Slot ID    Create Type             Actual Type             State
----------------------------------------------------------------
1          iscom5800e-ep4a         iscom5800e-ep4a         normal
2          iscom5800e-ep16         iscom5800e-ep16         normal
3          iscom5800-2pon          iscom5800-2pon          normal
4          iscom5800-2pon          iscom5800-2pon          normal
5          iscom5800-2pon          iscom5800-2pon          normal
6          iscom5800e-10gex2-2ge   iscom5800e-10gex2-2ge   normal
7          iscom5800e-smcb         iscom5800e-smcb         normal
8          iscom5800e-smcb         iscom5800e-smcb         normal
9          iscom5800-2pon          iscom5800-2pon          normal
10         iscom5800-2pon          iscom5800-2pon          normal
11         null                    null                    missing
12         null                    null                    missing
13         null                    null                    missing
14         power                   power                   normal
15         power                   power                   normal

论坛徽章:
769
金牛座
日期:2014-02-26 17:49:58水瓶座
日期:2014-02-26 18:10:15白羊座
日期:2014-04-15 19:29:52寅虎
日期:2014-04-17 19:43:21酉鸡
日期:2014-04-19 21:24:10子鼠
日期:2014-04-22 13:55:24卯兔
日期:2014-04-22 14:20:58亥猪
日期:2014-04-22 16:13:09狮子座
日期:2014-05-05 22:31:17摩羯座
日期:2014-05-06 10:32:53处女座
日期:2014-05-12 09:23:11子鼠
日期:2014-05-21 18:21:27
2 [报告]
发表于 2014-05-22 20:01 |只看该作者
本帖最后由 Herowinter 于 2014-05-22 20:03 编辑

回复 1# itpark
  1. awk '$2~/ep4a|ep4/{$0=$0" "$1"/1-4"} $2~/ep16/{$0=$0" "$1"/1-16"} $2~/2pon/{$0=$0" "$1"/1-2"}1' i
  2. Slot ID    Create Type             Actual Type             State
  3. ----------------------------------------------------------------
  4. 1          iscom5800e-ep4a         iscom5800e-ep4a         normal 1/1-4
  5. 2          iscom5800e-ep16         iscom5800e-ep16         normal 2/1-16
  6. 3          iscom5800-2pon          iscom5800-2pon          normal 3/1-2
  7. 4          iscom5800-2pon          iscom5800-2pon          normal 4/1-2
  8. 5          iscom5800-2pon          iscom5800-2pon          normal 5/1-2
  9. 6          iscom5800e-10gex2-2ge   iscom5800e-10gex2-2ge   normal
  10. 7          iscom5800e-smcb         iscom5800e-smcb         normal
  11. 8          iscom5800e-smcb         iscom5800e-smcb         normal
  12. 9          iscom5800-2pon          iscom5800-2pon          normal 9/1-2
  13. 10         iscom5800-2pon          iscom5800-2pon          normal 10/1-2
  14. 11         null                    null                    missing
  15. 12         null                    null                    missing
  16. 13         null                    null                    missing
  17. 14         power                   power                   normal
  18. 15         power                   power                   normal
复制代码

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
3 [报告]
发表于 2014-05-22 20:27 |只看该作者
体力活

论坛徽章:
32
处女座
日期:2013-11-20 23:41:20双子座
日期:2014-06-11 17:20:43戌狗
日期:2014-06-16 11:05:00处女座
日期:2014-07-22 17:30:47狮子座
日期:2014-07-28 15:38:17金牛座
日期:2014-08-05 16:34:01亥猪
日期:2014-08-18 13:34:25白羊座
日期:2014-09-02 15:03:55金牛座
日期:2014-11-10 10:23:58处女座
日期:2014-12-02 09:17:52程序设计版块每日发帖之星
日期:2015-06-16 22:20:002015亚冠之塔什干火车头
日期:2015-06-20 23:28:22
4 [报告]
发表于 2014-05-22 20:57 |只看该作者
若第2列包含ep4a或ep4

对于正则来说,只需要写ep4就可以了~{:2_172:}

论坛徽章:
769
金牛座
日期:2014-02-26 17:49:58水瓶座
日期:2014-02-26 18:10:15白羊座
日期:2014-04-15 19:29:52寅虎
日期:2014-04-17 19:43:21酉鸡
日期:2014-04-19 21:24:10子鼠
日期:2014-04-22 13:55:24卯兔
日期:2014-04-22 14:20:58亥猪
日期:2014-04-22 16:13:09狮子座
日期:2014-05-05 22:31:17摩羯座
日期:2014-05-06 10:32:53处女座
日期:2014-05-12 09:23:11子鼠
日期:2014-05-21 18:21:27
5 [报告]
发表于 2014-05-22 21:00 |只看该作者
回复 4# yestreenstars
...机械翻译楼主需求的默默路过...
   

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
6 [报告]
发表于 2014-05-23 15:10 |只看该作者
非常感谢!帮了大忙了

回复 2# Herowinter


   

论坛徽章:
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
7 [报告]
发表于 2014-05-23 15:31 |只看该作者
回复 2# Herowinter

combine your code together

$ awk 'match($0,/ep([0-9]+)|([0-9]+)pon/,a){$0=$0" "$1"/1-"a[1]a[2]}1' FILE
  1. Slot ID    Create Type             Actual Type             State
  2. ----------------------------------------------------------------
  3. 1          iscom5800e-ep4a         iscom5800e-ep4a         normal 1/1-4
  4. 2          iscom5800e-ep16         iscom5800e-ep16         normal 2/1-16
  5. 3          iscom5800-2pon          iscom5800-2pon          normal 3/1-2
  6. 4          iscom5800-2pon          iscom5800-2pon          normal 4/1-2
  7. 5          iscom5800-2pon          iscom5800-2pon          normal 5/1-2
  8. 6          iscom5800e-10gex2-2ge   iscom5800e-10gex2-2ge   normal
  9. 7          iscom5800e-smcb         iscom5800e-smcb         normal
  10. 8          iscom5800e-smcb         iscom5800e-smcb         normal
  11. 9          iscom5800-2pon          iscom5800-2pon          normal 9/1-2
  12. 10         iscom5800-2pon          iscom5800-2pon          normal 10/1-2
  13. 11         null                    null                    missing
  14. 12         null                    null                    missing
  15. 13         null                    null                    missing
  16. 14         power                   power                   normal
  17. 15         power                   power                   normal
复制代码

论坛徽章:
769
金牛座
日期:2014-02-26 17:49:58水瓶座
日期:2014-02-26 18:10:15白羊座
日期:2014-04-15 19:29:52寅虎
日期:2014-04-17 19:43:21酉鸡
日期:2014-04-19 21:24:10子鼠
日期:2014-04-22 13:55:24卯兔
日期:2014-04-22 14:20:58亥猪
日期:2014-04-22 16:13:09狮子座
日期:2014-05-05 22:31:17摩羯座
日期:2014-05-06 10:32:53处女座
日期:2014-05-12 09:23:11子鼠
日期:2014-05-21 18:21:27
8 [报告]
发表于 2014-05-23 15:36 |只看该作者
回复 7# jason680
多谢指点,我都没去找规律,结果的数字
4 16 2其实是在前面的正则匹配那个串里出现了,
这样做好多了。

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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP