0

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

user2641452
  • 105
  • 2
  • 10
  • With IFS=', ' mentioned in the https://stackoverflow.com/questions/10586153/split-string-into-an-array-in-bash , i am not able to split. Please help me – user2641452 Jan 14 '20 at 18:59
  • Please Reopen my question as string split IFS=", " didnt work for me. If someone can help me solving this problem using awk or se or any othher approach, please help me – user2641452 Jan 14 '20 at 20:59
  • You should edit the question to show what you tried. – Barmar Jan 14 '20 at 21:09
  • See https://meta.stackexchange.com/questions/36415/how-do-you-reopen-a-closed-question for how to request that your question be reopened – Barmar Jan 14 '20 at 21:10
  • 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 – user2641452 Jan 14 '20 at 21:39
  • You have to EDIT THE QUESTION – Barmar Jan 14 '20 at 21:39
  • `IFS=", "` makes *either* a comma or a space be treated as a separator, not the comma-space string. You don't want every space to be split on, so it's the Wrong Thing here. – Charles Duffy Jan 15 '20 at 13:57
  • ...I've edited the duplicate list, adding a question that explicitly covers the multi-character separator case. The OP there wanted to split into lines rather than array elements, but once you have lines, it's just as easy as feeding that into `mapfile` or `readarray` (as in, `readarray -t arrayname < <(...code that generates lines...)`). – Charles Duffy Jan 15 '20 at 13:58
  • Any pointers to the solution for the question above? – user2641452 Jan 15 '20 at 19:06

0 Answers0