String manipulation using Korn Shell Scripts in Unix

I have a string "uid=1003(user1) gid=101(groupxyz)" which is result of the execution of the shell command "id" in Unix.
Now I need to parse this above string and get the username i.e. "user1" in the above example.
Can anyone give me any clue in this and yes I can't use the obvious $LOGNAME in this case, I will have to get the current username using "id".
ch_kaushikAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ozoConnect With a Mentor Commented:
echo $string | cut -f2 -d'(' | cut -f1 -d')'
0
 
ravs120499Commented:
echo $string | cut -f2 -d'=' | cut -f1 -d'('

will do the job if the string will always be in exactly the same format, i.e. the uid starts immediately after the '=' and the parentheses starts immediately after the uid.

If you want more sophistication, you can also try sed or awk.

Regards
0
All Courses

From novice to tech pro — start learning today.