免费注册 查看新帖 |

Chinaunix

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

如果筛选文件中指定的字段呢 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-27 14:31 |只看该作者 |倒序浏览
如下的信息是我从ldap服务器中export出来的ldif文件其中两条记录:
  1. # entry-id: 5080
  2. dn: uid=youny,ou=people,o=abc.com.cn,o=isp
  3. modifyTimestamp: 20081217125108Z
  4. modifiersName: cn=puser,ou=dsame users,o=isp
  5. mailDeliveryOption: mailbox
  6. userPassword: {SSHA}BYHBNfanq4LiQ4EkE7yflve9yXwFfKcStCp1Jg==
  7. mailQuota: 20M
  8. nswmExtendedUserPrefs: meDraftFolder=Drafts
  9. nswmExtendedUserPrefs: meSentFolder=Sent
  10. nswmExtendedUserPrefs: meTrashFolder=Trash
  11. nswmExtendedUserPrefs: meInitialized=true
  12. nswmExtendedUserPrefs:: dkNhcmQ9YmVnaW5cM2F2Y2FyZCRuXDNh6LSi5Yqh6YOo57uP55CG5
  13. Y2e5L2z5bOwO+S4iua1t+enkeaKgOe9kee7nOmAmuiur+aciemZkOWFrOWPuCRmblwzYeS4iua1t
  14. +enkeaKgOe9kee7nOmAmuiur+aciemZkOWFrOWPuCDotKLliqHpg6jnu4/nkIbljZ7kvbPls7Akd
  15. GVsO2NlbGxcM2ExMzcwMTc0MDk0NyR0ZWw7d29ya1wzYTY0NjQwMzU2JGFkclwzYTs75LiK5rW35
  16. biC5Lit5bGx6KW/6LevMTUyNeWPtzbmpbw75LiK5rW3OzsyMDAyMzU75Lit5Zu9JHZlcnNpb25cM
  17. 2EyLjEkZW1haWw7aW50ZXJuZXRcM2FqZmJpYW5Ac3RuYy5jb20uY24kZW5kXDNhdmNhcmQk
  18. nswmExtendedUserPrefs: meViewSize=100
  19. nswmExtendedUserPrefs: meDateFormat=0/
  20. preferredLanguage: zh_CN
  21. mailForwardingAddress: [email]bianjf@abc.com.cn[/email]
  22. cn:: U1ROQyDljZ7kvbPls7A=
  23. sn:: 5Y2e5L2z5bOw
  24. givenName: STNC
  25. preferredLocale: zh_CN
  26. psIncludeInGAB: false
  27. mailMsgQuota: 500
  28. nsUniqueId: 4eb89778-510411db-8003aacb-ecbda64c
  29. mailHost: dse.abc.com.cn
  30. mailUserStatus: active
  31. nsdaCapability: mailListCreate
  32. mail: [email]youny@abc.com.cn[/email]
  33. objectClass: top
  34. objectClass: person
  35. objectClass: organizationalPerson
  36. objectClass: inetOrgPerson
  37. objectClass: inetUser
  38. objectClass: ipUser
  39. objectClass: nsManagedPerson
  40. objectClass: userPresenceProfile
  41. objectClass: inetMailUser
  42. objectClass: inetLocalMailRecipient
  43. objectClass: inetAdmin
  44. objectClass: iplanet-am-user-service
  45. objectClass: iplanet-am-managed-person
  46. objectClass: iPlanetPreferences
  47. objectClass: inetsubscriber
  48. inetUserStatus: active
  49. uid: youny
  50. dataSource: NDA 4.5 Delegated Administrator
  51. pabURI: ldap://dse.abc.com.cn:389/ou=youny,ou=people,o=abc.com.cn,o=isp,o=pab
  52. creatorsName: cn=directory manager
  53. createTimestamp: 20071001042201Z
  54. iplanet-am-modifiable-by: cn=Top-level Admin Role,o=isp

  55. # entry-id: 5081
  56. dn: uid=jiangy,ou=people,o=kiiy.cn,o=isp
  57. modifyTimestamp: 20081217125108Z
  58. modifiersName: cn=puser,ou=dsame users,o=isp
  59. mailDeliveryOption: mailbox
  60. userPassword: {SSHA}BYHBNfanq4LiQ4EkE7yflve9yXwFfKcStCp1Jg==
  61. mailQuota: 50M
  62. nswmExtendedUserPrefs: meDraftFolder=Drafts
  63. nswmExtendedUserPrefs: meSentFolder=Sent
  64. nswmExtendedUserPrefs: meTrashFolder=Trash
  65. nswmExtendedUserPrefs: meInitialized=true
  66. nswmExtendedUserPrefs:: dkNhcmQ9YmVnaW5cM2F2Y2FyZCRuXDNh6LSi5Yqh6YOo57uP55CG5
  67. Y2e5L2z5bOwO+S4iua1t+enkeaKgOe9kee7nOmAmuiur+aciemZkOWFrOWPuCRmblwzYeS4iua1t
  68. +enkeaKgOe9kee7nOmAmuiur+aciemZkOWFrOWPuCDotKLliqHpg6jnu4/nkIbljZ7kvbPls7Akd
  69. GVsO2NlbGxcM2ExMzcwMTc0MDk0NyR0ZWw7d29ya1wzYTY0NjQwMzU2JGFkclwzYTs75LiK5rW35
  70. biC5Lit5bGx6KW/6LevMTUyNeWPtzbmpbw75LiK5rW3OzsyMDAyMzU75Lit5Zu9JHZlcnNpb25cM
  71. 2EyLjEkZW1haWw7aW50ZXJuZXRcM2FqZmJpYW5Ac3RuYy5jb20uY24kZW5kXDNhdmNhcmQk
  72. nswmExtendedUserPrefs: meViewSize=100
  73. nswmExtendedUserPrefs: meDateFormat=0/
  74. preferredLanguage: zh_CN
  75. mailForwardingAddress: [email]jiangy@kiiy.cn[/email]
  76. cn:: U1ROQyDljZ7kvbPls7A=
  77. sn:: 5Y2e5L2z5bOw
  78. givenName: STNC
  79. preferredLocale: zh_CN
  80. psIncludeInGAB: false
  81. mailMsgQuota: 500
  82. nsUniqueId: 4eb89778-510411db-8003aacb-ecbda64c
  83. mailHost: dse.abc.com.cn
  84. mailUserStatus: active
  85. nsdaCapability: mailListCreate
  86. mail: [email]jiangy@kiiy.cn[/email]
  87. objectClass: top
  88. objectClass: person
  89. objectClass: organizationalPerson
  90. objectClass: inetOrgPerson
  91. objectClass: inetUser
  92. objectClass: ipUser
  93. objectClass: nsManagedPerson
  94. objectClass: userPresenceProfile
  95. objectClass: inetMailUser
  96. objectClass: inetLocalMailRecipient
  97. objectClass: inetAdmin
  98. objectClass: iplanet-am-user-service
  99. objectClass: iplanet-am-managed-person
  100. objectClass: iPlanetPreferences
  101. objectClass: inetsubscriber
  102. inetUserStatus: active
  103. uid: jiangy
  104. dataSource: NDA 4.5 Delegated Administrator
  105. pabURI: ldap://dse.abc.com.cn:389/ou=jiangy,ou=people,o=kiiy.cn,o=isp,o=pab
  106. creatorsName: cn=directory manager
  107. createTimestamp: 20071001042201Z
  108. iplanet-am-modifiable-by: cn=Top-level Admin Role,o=isp
复制代码


从上面的信息中,我知道如果当记录中以dn:开头并含有o=abc.com.cn,o=isp字符的,是属于abc.com.cn的域帐号LDAP记录.

从# entry-id: 5080可以看出,我export出来的ldif文件中有5000多条这样的记录,现在我想筛选出每条记录的部分字段,例如,
当记录中以dn:开头并含有o=abc.com.cn,o=isp字符的,打印以如下字符开头的字段:
  1. # entry-id:
  2. dn:
  3. mailDeliveryOption:
  4. mailQuota:
  5. mailUserStatus:
  6. mail:
  7. mailAlternateAddress:
  8. uid:
  9. userPassword:
  10. givenName:
  11. mailForwardingAddress:
  12. sn:
  13. cn:
  14. mailMsgQuota:
复制代码


谢谢.

[ 本帖最后由 netocool 于 2009-8-28 10:04 编辑 ]

论坛徽章:
1
数据库技术版块每日发帖之星
日期:2016-01-24 06:20:00
2 [报告]
发表于 2009-08-27 14:40 |只看该作者
是这样?

  1. egrep '^# entry-id:|^dn:|^mailDeliveryOption:|^mailQuota:|^mailUserStatus:|^mail:|^mailAlternateAddress:|^uid:|^userPassword:|^givenName:|^mailForwardingAddress:|^sn:|^cn:|^mailMsgQuota:' urfile
复制代码

论坛徽章:
0
3 [报告]
发表于 2009-08-27 14:49 |只看该作者

回复 #1 netocool 的帖子

egrep -o '^(dn|mailDeliveryOption|mailQuota|mailUserStatus|mail|mailAlternateAddress|uid|userPassword|givenName|mailForwardingAddress|sn|cn|mailMsgQuota):' urfile

[ 本帖最后由 greendays 于 2009-8-27 14:50 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2009-08-27 15:04 |只看该作者
原帖由 greendays 于 2009-8-27 14:49 发表
egrep -o '^(dn|mailDeliveryOption|mailQuota|mailUserStatus|mail|mailAlternateAddress|uid|userPassword|givenName|mailForwardingAddress|sn|cn|mailMsgQuota):' urfile



好像不行

在字段
  1. dn: uid=youny,ou=people,o=abc.com.cn,o=isp
复制代码
中,根据ou=people,o=abc.com.cn这个字符来区分此记录是属于那个domain的.

请问如何呢?谢谢

论坛徽章:
0
5 [报告]
发表于 2009-08-27 15:13 |只看该作者
我的思路是这样的
  1. ^dn:
复制代码
中包含
  1. ou=people, o=abc.com.cn,o=isp
复制代码
,那么此记录是属于域名abc.com.cn的信息

我需要筛选出来的结果:
  1. # entry-id: 5066
  2. dn: uid=jianc, ou=people, o=abc.com.cn,o=isp
  3. mailQuota: 50M
  4. cn:: 5LiK5rW356eR5oqA572R57uc6YCa5L+h5pyJ6ZmQ5YWs5Y+4IOe9kee7nOi/kOe7tOmDqOWA
  5. vOePrSDnjovnkKY=
  6. sn:: 572R57uc6L+Q57u06YOo5YC854+tIOeOi+eQpg==
  7. mail: [email]jianc@abc.com.cn[/email]
  8. mailAlternateAddress: [email]webmaster@abc.com.cn[/email]
  9. uid: jianc
  10. givenName:: 5LiK5rW356eR5oqA572R57uc6YCa5L+h5pyJ6ZmQ5YWs5Y+4
  11. ......

  12. # entry-id: 5067
  13. dn: uid=tommy, ou=people, o=abc.com.cn,o=isp
  14. mailQuota: 50M
  15. cn:: 5LiK5rW356eR5oqA5723457uc6YCa5L+gt5pyJ6ZmQ5YWs5Y+4IOe9kee7nOi/kOe7tOmDqOWA
  16. vOePrSDnjovnkKY=
  17. sn:: 572R57uc6L+Q5er46YOo5YC854+tIOeOi+eQpg==
  18. mail: [email]tommy@abc.com.cn[/email]
  19. mailAlternateAddress: [email]tiy@abc.com.cn[/email]
  20. uid: tommy
  21. givenName:: 5LiK5rW356ert67572R57uc6YCa5L+h5pyJ6ZmQ5YWs5Y+4
  22. ......

复制代码

论坛徽章:
0
6 [报告]
发表于 2009-08-27 15:38 |只看该作者

回复 #4 netocool 的帖子

egrep  '^(# entry-id|dn|mailDeliveryOption|mailQuota|mailUserStatus|mail|mailAlternateAddress|uid|userPassword|givenName|mailForwardingAddress|sn|cn|mailMsgQuota):' urfile

论坛徽章:
0
7 [报告]
发表于 2009-08-27 16:26 |只看该作者

回复 #1 netocool 的帖子

完全看不懂啊

论坛徽章:
0
8 [报告]
发表于 2009-08-28 10:04 |只看该作者
我也是在学习阶段,请大家多多指教,谢谢.

论坛徽章:
0
9 [报告]
发表于 2009-08-28 10:14 |只看该作者

回复 #8 netocool 的帖子

你的问题解决了吗?

[ 本帖最后由 greendays 于 2009-8-28 10:16 编辑 ]

论坛徽章:
0
10 [报告]
发表于 2009-08-28 10:24 |只看该作者
原帖由 greendays 于 2009-8-28 10:14 发表
你的问题解决了吗?


没有达到我的要求,呵呵
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP