2

I have a file like this on a Linux machine:

dn: cn=333-MMMM-PPPP_DET1,ou=groups,ou=functional,o=company
member: cn=aaa,ou=users,ou=accounts,o=company
member: cn=bbb,ou=users,ou=accounts,o=company
member: cn=ccc,ou=users,ou=accounts,o=company
member: cn=ddd,ou=users,ou=accounts,o=company
member: cn=eee,ou=users,ou=accounts,o=company

dn: cn=333-MMMM-PPPP_DET2,ou=groups,ou=functional,o=company

dn: cn=333-MMMM-PPPP_DET3,ou=groups,ou=functional,o=company
member: cn=aaa,ou=users,ou=accounts,o=company
member: cn=ggg,ou=users,ou=accounts,o=company
 

And I would like to convert it to get an easy formatted csv to import in further applications:

aaa;333-MMMM-PPPP_DET1 
bbb;333-MMMM-PPPP_DET1
ccc;333-MMMM-PPPP_DET1
ddd;333-MMMM-PPPP_DET1
eee;333-MMMM-PPPP_DET1
aaa;333-MMMM-PPPP_DET3
ggg;333-MMMM-PPPP_DET3

I already tried: awk '1;/^$/{exit} -> show all lines until the first break (the plan was to print them, move it to another file and then delete them. In a loop. awk 'FNR == 1 {suffix=$0} {print $0suffix}' -> take the first line and put it to the end of all other lines.

I didn't find a way to solve this. Any suggestions?

1
1
$ awk -F'[,=]' -v OFS=',' '/^dn/{dn=$2} /^me/{print $2, dn}' file
aaa,333-MMMM-PPPP_DET1
bbb,333-MMMM-PPPP_DET1
ccc,333-MMMM-PPPP_DET1
ddd,333-MMMM-PPPP_DET1
eee,333-MMMM-PPPP_DET1
aaa,333-MMMM-PPPP_DET3
ggg,333-MMMM-PPPP_DET3
1
  • 1
    Great, that works fine! Thanks a lot, Ed! – eimi May 4 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.