Solved

String manipulation using Korn Shell Scripts in Unix

Posted on 2004-10-08
2
294 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
Comment Utility
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
Comment Utility
echo $string | cut -f2 -d'(' | cut -f1 -d')'
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 81
pre4 challenge 19 87
changeXy challenge 13 56
How To Loop - Python 19 65
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

772 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

12 Experts available now in Live!

Get 1:1 Help Now