Solved

String manipulation using Korn Shell Scripts in Unix

Posted on 2004-10-08
2
306 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mirrorEnds challenge 6 94
sum28 challenge 31 106
factory design pattern vs abstract factoy design pattern 2 100
noX challenge 17 92
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

895 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

13 Experts available now in Live!

Get 1:1 Help Now