I want to split a string and need some parameters from it.
USER="dn: uid=dfl3030,cn=users,cn=accounts,dc=tenant,dc=ycs,dc=io cn: Reb Lena Schmidt krbpasswordexpiration: 20200415235959Z mail: arl0031@tenant.ycs.io mail: rebecca-lena.schmidt@arlanxeo.com"
Want Below Parameters from the USER string as ->
UserId=dfl3030
Name=Reb Lena Schmidt
PwdExpiry=20200415235959Z
Email=rebecca-lena.schmidt@arlanxeo.com ( Second mail not the first one)
Can someone can help me to split it.
I am able to retrieve UserID with below command
echo $USER | awk -F= '{print $2}'| cut -d "," -f 1
and it is working. But for Name if i do echo $USER | awk '{print $4}' it shows first name only. I don't want to hardcode awk (print NUMBER) as name can have one or two or three words. Please help to retreive the name and the second email