1

伙计们,我需要根据 10k 记录列表在 ldap 上添加一系列条目。我有以下代码:

awk -v uid=999905284 '
{
print "dn: uid="$0",ou=aaa,ou=bbb,dc=br\n
uid: "$0"\n
sn: "$0"\n
cn: "$0"\n
mail: "$0"@grupos.a.br\n
description: "$0"\n
phpgwAccountType: l\n
phpgwAccountStatus: A\n
uidNumber: "uid++"\n
gidNumber: 0\n
deliveryMode: forwardOnly\n
accountStatus: active\n
defaultMemberModeration: 1\n"
}' list

list的输入如下:

list-a
list-b
...
list-n

样本预期输出:

dn: uid=list-a,ou=aaa,ou=bbb,dc=br\n
uid: list-a
sn: list-a
cn: list-a
mail: list-a@grupos.a.br
description: list-a
phpgwAccountType: l
phpgwAccountStatus: A
uidNumber: 999905284
gidNumber: 0
deliveryMode: forwardOnly
accountStatus: active
defaultMemberModeration: 1


dn: uid=list-b,ou=aaa,ou=bbb,dc=br\n
uid: list-b
sn: list-b
cn: list-b
mail: list-b@grupos.a.br
description: list-b
phpgwAccountType: l
phpgwAccountStatus: A
uidNumber: 999905285
gidNumber: 0
deliveryMode: forwardOnly
accountStatus: active
defaultMemberModeration: 1

我希望输出 $0 将替换为列表的名称,但它不起作用。

提前致谢!

4

1 回答 1

2

awk不允许您将带引号的字符串拆分为两行,除非您通过\在末尾放置 a 将每一行标记为续行。由于您已经\n明确地包含在输出中,您可以通过将继续标记放置在引用字符串被拆分的任何地方来解决问题:

awk -v uid=999905284 '
{
print "dn: uid="$0",ou=aaa,ou=bbb,dc=br\n\
uid: "$0"\n\
sn: "$0"\n\
cn: "$0"\n\
mail: "$0"@grupos.a.br\n\
description: "$0"\n\
phpgwAccountType: l\n\
phpgwAccountStatus: A\n\
uidNumber: "uid++"\n\
gidNumber: 0\n\
deliveryMode: forwardOnly\n\
accountStatus: active\n\
defaultMemberModeration: 1\n"
}' list
于 2013-07-31T02:57:06.733 回答