Solved

String manipulation using Korn Shell Scripts in Unix

Posted on 2004-10-08
2
314 Views
Last Modified: 2008-03-06
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".
0
Comment
Question by:ch_kaushik
2 Comments
 
LVL 7

Expert Comment

by:ravs120499
ID: 12259173
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
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 12267196
echo $string | cut -f2 -d'(' | cut -f1 -d')'
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Setup specific permissions in Microsoft Access 9 57
has22 challenge 11 92
data scientists and AI 17 107
WPF - Tooltips for ComboBox items 5 67
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now