Regular expressions output is whole line

Hi,
I am newbie in shell programming and I need some help.

I had some data and I format it in a file like

dn: uid=aaaaa, dc=exmple, dc=com
cn: bbbb cccc
sn: cccc
telephoneNumber:+30-6543-123456

I have to extract the information aaaaa , bbbb, cccc and the phone number
using awk expressions

I am trying regular expressions like

awk '/dn: uid=[a-zA-Z]/ { print }' 1.txt

but the output is the whole line (not only the username)

can I save this info to arrays like usernames[] , firstnames[], lastnames[]

because I want to do something else later.

Thanks a lot for your help

$ cat mytst
dn: uid=aaaaa, dc=exmple, dc=com
cn: bbbb cccc
sn: cccc
telephoneNumber:+30-6543-123456

$ awk -F"[ :=,]" '/^d/{x=4}/^[cs]n/{x=3}/^tel/{x=2}x{print $x;x=y}' mytst
aaaaa
bbbb
cccc
+30-6543-123456
$
1 Like
nawk -F'[=,: ]' '{print /uid=/?$4:(/^telephoneN/)?$2:$3}' myFile
1 Like

thanks a lot