pelama
August 6, 2012, 5:00pm
1
Hi.. I have this delicate problem..:wall: I have this huge ldif file with entry's like this example below..
And I need to change the following entrys.
telephoneNumber:
emNotifNumber:
billingnumber=
BillingNumber:
Al these entrys has a number like 012345678 and it needs to add one more number in begining,, like 9012345678
So
telephoneNumber:012345678 needs to be change to telephoneNumber:9012345678 and so on..
this is a huge file so I would like this to run in one go..
So... How would I do this?
# entry-id: 192
dn: uniqueidentifier=um704,ou=C10,ou=site1,o=users
nsUniqueId: a7e6a34b-1dd111b2-80f1bd80-559f9638
modifyTimestamp: 20090617001511Z
modifiersName: uniqueidentifier=um9999999999999999,o=users
mailHost: mail.sugar.pop.us
mailAlternateAddress: 012345678@sugar.pop.us
emFTL: -1,F
BadLoginCount: 0
umpassword: password
Password: password
mailForwardingAddress: 123123@sugar.pop.com
cn: SUGAR POP
sn: SUGAR
givenName: POP
uniqueIdentifier: um704
uid: 012345678
telephoneNumber: 012345678
mailQuota: 7549747
mail: 012345678@sugar.pop.com
emNotifNumber: 012345678
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: nsmessagingserveruser
objectClass: inetmailuser
objectClass: inetlocalmailrecipient
objectClass: LIP
objectClass: emuser
objectClass: emNotification
gender: F
l: 0
preferredLanguage: en
emMessagecharencoding: ISO-8859-1
mailDeliveryOption: mailbox
mailDeliveryOption: forward
emSMPPcenterid: SMSC
emPreferredDateFormat: yyyy/mm/dd
emPreferredTimeFormat: 24
userPassword: userpassword
creatorsName: cn=directory manager
createTimestamp: 20031201054612Z
emServiceDn: cos=20,ou=C10,ou=site1,o=users
# entry-id: 193
dn: billingnumber=012345678,uniqueIdentifier=um704,ou=C10,ou=site1,o=users
nsUniqueId: a7e6a34c-1dd111b2-80f1bd80-559f9638
modifyTimestamp: 20090617001511Z
modifiersName: uniqueidentifier=um9999999999999999,o=users
admininfo: uniqueidentifier=um1p383
BillingNumber: 012345678
AnsweringService: LM
objectClass: top
objectClass: confmsgbox
subscribertimezone: bluemoon/mars
creatorsName: cn=directory manager
createTimestamp: 20031201054612Z
ActiveGreetingId: SpokenName,AllCalls
COSDN: cos=20, ou=C10, ou=site1,o=users
How about this:
awk -F": " -v prefix=9 -v vals=telephoneNumber,emNotifNumber,billingnumber,BillingNumber '
BEGIN{OFS=": ";split(vals,tmp,","); for(val in tmp) V[tmp[val]]}
$1 in V { $2=prefix $2} 1' infile
pelama
August 7, 2012, 12:42am
3
Yes.. That almost works..
# entry-id: 192
dn: uniqueidentifier=um704,ou=C10,ou=site1,o=users
nsUniqueId: a7e6a34b-1dd111b2-80f1bd80-559f9638
modifyTimestamp: 20090617001511Z
modifiersName: uniqueidentifier=um9999999999999999,o=users
mailHost: mail.sugar.pop.us
mailAlternateAddress: 012345678@sugar.pop.us
emFTL: -1,F
BadLoginCount: 0
umpassword: password
Password: password
mailForwardingAddress: 123123@sugar.pop.com
cn: SUGAR POP
sn: SUGAR
givenName: POP
uniqueIdentifier: um704
uid: 012345678
telephoneNumber: 9012345678
mailQuota: 7549747
mail: 012345678@sugar.pop.com
emNotifNumber: 9012345678
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: nsmessagingserveruser
objectClass: inetmailuser
objectClass: inetlocalmailrecipient
objectClass: LIP
objectClass: emuser
objectClass: emNotification
gender: F
l: 0
preferredLanguage: en
emMessagecharencoding: ISO-8859-1
mailDeliveryOption: mailbox
mailDeliveryOption: forward
emSMPPcenterid: SMSC
emPreferredDateFormat: yyyy/mm/dd
emPreferredTimeFormat: 24
userPassword: userpassword
creatorsName: cn=directory manager
createTimestamp: 20031201054612Z
emServiceDn: cos=20,ou=C10,ou=site1,o=users
# entry-id: 193
dn: billingnumber=012345678,uniqueIdentifier=um704,ou=C10,ou=site1,o=users
nsUniqueId: a7e6a34c-1dd111b2-80f1bd80-559f9638
modifyTimestamp: 20090617001511Z
modifiersName: uniqueidentifier=um9999999999999999,o=users
admininfo: uniqueidentifier=um1p383
BillingNumber: 9012345678
AnsweringService: LM
objectClass: top
objectClass: confmsgbox
subscribertimezone: bluemoon/mars
creatorsName: cn=directory manager
createTimestamp: 20031201054612Z
ActiveGreetingId: SpokenName,AllCalls
COSDN: cos=20, ou=C10, ou=site1,o=users
The dn entry for billing number did not change..
Not quite as elegant, but I kept the flexibility of the original solution:
awk -F": " -v add=9 -v vals=telphoneNumber,emNotifNumber,billingnumber,BillingNumber '
BEGIN{OFS=": ";split(vals,tmp,","); for(val in tmp) V[tmp[val]]}
$1 in V { $2=add $2}
/=/ {for(str in V) gsub(str"=", str"="add)} 1' infile
pelama
August 8, 2012, 4:23pm
5
This worked as Charm in my mac,
Then I lifted it out to my Solaris10,
and because this is way over my head now,, I don't know what went wrong..
awk -F ": " -v add=9 -v vals=telephoneNumber,emNotifNumber,billingnumber,BillingNumber '
BEGIN{OFS=": ";split(vals,tmp,","); for(val in tmp) V[tmp[val]]}
$1 in V { $2=add $2}
/=/ {for(str in V) gsub(str"=", str"="add)} 1' userdb
awk: syntax error near line 1
awk: bailing out near line 1
awk -F ": " -v add=9 -v userdb 0.00s user 0.00s system 0% cpu 0.009 total
I'm really glad you helping me out here Chubler
pelama
August 8, 2012, 4:32pm
7
# time nawk -F": " -v add=9 -v vals=telephoneNumber,emNotifNumber,billingnumber,BillingNumber '
BEGIN{OFS=": ";split(vals,tmp,","); for(val in tmp) V[tmp[val]]}
$1 in V { $2=add $2}
/=/ {for(str in V) gsub(str"=", str"="add)} 1' userdb
nawk: syntax error at source line 4
context is
>>> /= <<<
nawk: bailing out at source line 4
nawk -F": " -v add=9 -v userdb 0.00s user 0.00s system 0% cpu 0.009 total
I don't have access to Solaris/Awk to try it out, but this different approach might work:
nawk -F": " -v add=9 -v vals=telphoneNumber,emNotifNumber,billingnumber,BillingNumber '
BEGIN{OFS=": ";split(vals,tmp,","); for(val in tmp) V[tmp[val]]}
$1 in V {$2=add $2}
$0~"=" {for(str in V) gsub(str"=", str"="add)} 1' infile
pelama
August 8, 2012, 4:52pm
9
Why do you know these things. LOL
When you've lived on a farm as long as I have you learn to side step problems like that, LOL.
pelama
September 6, 2012, 4:02pm
12
When I thought everything was hunky-dory
the first scenario was changing the numbers 01234567 to 901234567 and of course this was scenario changed.
Now I need to change the number from 01234567 to 091234567
Is that hard to change?
How about:
nawk -F": " -v add=9 -v vals=telphoneNumber,emNotifNumber,billingnumber,BillingNumber '
BEGIN{OFS=": ";split(vals,tmp,","); for(val in tmp) V[tmp[val]]}
$1 in V {sub("^0*", "&"add, $2)}
$0~"=" {for(str in V) gsub(str"=0*", "&"add)} 1' infile
pelama
September 6, 2012, 6:05pm
14
Seem to work fine.
I'm trying to understand,, what is does.. But.. No.. I don't get inte.. but a question,.
this "^0*" is that when it starts with a 0 or?
Thanks even more.. this time..
Another approach may be:
sed 's/\([nN]umber[: =]*\)0/\109/g' infile
pelama
September 18, 2012, 9:56am
16
Nice.. Thanks.. I will try this one as well.. Thanks a lot