Chinaunix首页 | 论坛 | 博客

XX

  • 博客访问: 491026
  • 博文数量: 281
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 562
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-17 21:40
个人简介

XXX

文章分类

全部博文(281)

文章存档

2017年(1)

2015年(3)

2014年(117)

2013年(160)

我的朋友

分类: LINUX

2013-03-26 11:56:43

第一个练习,你的输入是按照下列形式的行:

Username:Firstname:Lastname:Telephone number

写一个把这样的行转换成一个如下LDAP记录格式的 awk 脚本:

dn: uid=Username, dc=example, dc=com
cn: Firstname Lastname
sn: Lastname
telephoneNumber: Telephone number 

建立并检查一个包含一系列测试记录的文件。

完成awk脚本文件如下:

BEGIN { FS=":" }
{ print "dn: uid=" $1 ", dc=example, dc=com" }
{ print "cn: " $2, $3 }
{ print "sn: " $3 }
{ print "telephoneNumber: " $4 }

测试:

[armlinux@lqm practice]$ awk -f testawk1 test
dn: uid=Username, dc=example, dc=com
cn: Firstname Lastname
sn: Lastname
telephoneNumber: Telephone number

awk脚本还可以更改为:

[armlinux@lqm practice]$ cat testawk
BEGIN { FS=":" }
{ print "dn: uid=" $1 ", dc=example, dc=com\ncn: " $2, $3 "\nsn: " $3 "\ntelephoneNumber: " $4 }

习题二(2007-02-08)

以下列格式为准从 Tab分割列表中建立XML风格输出:

Meaning very long line with a lot of description
 
meaning another long line
 
othermeaning    more longline
 
testmeaning     loooline, but i mean really ooong. 

输出像这样:


Meaning

very long line



meaning

long line





more longline





loooline, but i mean really ooong.

[armlinux@lqm practice]$ cat xml
Meaning very long line with a lot of description
meaning another long line
othermeaning more longline
testmeaning loooooooooooooooooooooline, but I mean really looooooooo
[armlinux@lqm practice]$ cat testxml
BEGIN { FS="\t" }
{ print "" }
{ print "" $1 "" }
{ print "" }
{ print $2 }
{ print ""}
{ print "" }
[armlinux@lqm practice]$ awk -f testxml xml
<row>
<entry>Meaning</entry>
<entry>
very long line with a lot of description
</entry>
</row>
<row>
<entry>meaning</entry>
<entry>
another long line
</entry>
</row>
<row>
<entry>othermeaning</entry>
<entry>
more longline
</entry>
</row>
<row>
<entry>testmeaning</entry>
<entry>
loooooooooooooooooooooline, but I mean really looooooooo
</entry>
</row>


阅读(686) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~