1

Folks I need to add a serie of entries on an ldap based on a 10k records list. I have the following code:

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

The input of list is as follows:

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

Sample expected output:

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

I would expect an output where the $0 would be replaced by the name of the lists thou it is not working.

Thanks in advance!

larsks
  • 277,717
  • 41
  • 399
  • 399
vfbsilva
  • 135
  • 8
  • 1
    How is it not working? Are you getting errors? Unexpected output? – larsks Jul 31 '13 at 02:03
  • 1
    +1 for good first question with sample data, required output. Just show us the current machine output or errors. OR are any of your files created on MSWindows and then moved to linux? If so, then `dos2unix myScript myDataFile ....` . Good luck! – shellter Jul 31 '13 at 02:24

1 Answers1

2

awk doesn't allow you to split quoted strings over two lines, unless you mark each line as a continuation by putting a \ at the end. Since you are already including \n in the output explicitly, you can just fix things up by putting the continuation markers everywhere a quoted string is split:

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
rici
  • 234,347
  • 28
  • 237
  • 341
  • Still not working properly. Something is amiss awk: ./adiciona_listas_massa:2: awk -v uid=999905284 ' awk: ./adiciona_listas_massa:2: ^ syntax error awk: ./adiciona_listas_massa:2: awk -v uid=999905284 ' awk: ./adiciona_listas_massa:2: ^ invalid char ''' in expression I've looked for unicode chars or something else which might be the problem. No luck. – vfbsilva Jul 31 '13 at 13:22