Extraindo informações de entradas em um arquivo LDIF

1

Eu tenho um arquivo que contém entradas como esta:

ddn: cn=312548,ou=Entities,ou=Active,ou=Vault,o=abc
member: cn=312548001,ou=Unnamed,ou=Identities,ou=Active,ou=Vault,o=abc
member: cn=312548999,ou=ServiceAccounts,ou=Active,ou=Vault,o=abc
abcName: something else

dn: cn=312544,ou=Entities,ou=Active,ou=Vault,o=abc
member: cn=312544001,ou=Unnamed,ou=Identities,ou=Active,ou=Vault,o=abc
member: cn=312544999,ou=ServiceAccounts,ou=Active,ou=Vault,o=abc
abcName: after bike

dn: cn=312542,ou=Entities,ou=Active,ou=Vault,o=abc
member: cn=312542001,ou=Unnamed,ou=Identities,ou=Active,ou=Vault,o=abc
member: cn=312542999,ou=ServiceAccounts,ou=Active,ou=Vault,o=abc
abcName: pen mark

dn: cn=312539,ou=Entities,ou=Active,ou=Vault,o=abc
member: cn=312539999,ou=ServiceAccounts,ou=Active,ou=Vault,o=abc
member: cn=312539001,ou=Unnamed,ou=Identities,ou=Active,ou=Vault,o=abc
abcName: used car

dn: cn=312537,ou=Entities,ou=Active,ou=Vault,o=abc
member: cn=312537001,ou=Unnamed,ou=Identities,ou=Active,ou=Vault,o=abc
member: cn=312537999,ou=ServiceAccounts,ou=Active,ou=Vault,o=abc
abcName: Book bike

dn: cn=312534,ou=Entities,ou=Active,ou=Vault,o=abc
member: cn=312534999,ou=ServiceAccounts,ou=Active,ou=Vault,o=abc
member: cn=312534001,ou=Unnamed,ou=Identities,ou=Active,ou=Vault,o=abc
member: cn=fe7316f7-05d6-439b-8b9b-4364f4936615,ou=Named,ou=Identities,ou=Acti
 ve,ou=Vault,o=abc
abcName: Apple

Agora eu quero saber apenas as entradas dn que possuem um membro "Nomeado".

A saída deve conter o "abcName" e o "dn".

    
por user120136 22.06.2015 / 11:36

2 respostas

2

Na sua amostra,

awk -vRS= -F': *|\n' '/,ou=Named,/{print $2, $NF}' < file

produziria:

cn=312534,ou=Entities,ou=Active,ou=Vault,o=abc Apple

(que assume abcName como o último atributo de cada entrada e que ,ou=Named, não pode ser encontrado em outros atributos ou dn , e que os valores dos atributos não são codificados).

Para contabilizar as continuações de linha LDIF (onde, por exemplo, ou=Named pode se tornar ou=Na\n med ), primeiro é possível removê-las:

awk -vRS= -F': *|\n' '{gsub(/\n /, "")}; /,ou=Named,/{print $2, $NF}' < file
    
por 22.06.2015 / 11:51
3

Com o GNU sed

sed 'H;/^$/{h};/abcName/{x;/,ou=Named,/{s/member:[^\n]*\n//g;p}};d' file

dn: cn=312534,ou=Entities,ou=Active,ou=Vault,o=abc
abcName: Apple
    
por 22.06.2015 / 12:20