[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

String manipulation using Korn Shell Scripts in Unix

Posted on 2004-10-08
2
Medium Priority
?
343 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 85

Accepted Solution

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
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.
Suggested Courses

867 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