LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-21-2004, 03:05 AM   #1
MurrayL
LQ Newbie
 
Registered: Feb 2004
Location: South Africa
Distribution: RedHat 9.0
Posts: 22

Rep: Reputation: 15
Bash Script String Splitting


Hi.
I am trying to write a bash script that reads usefull information from the /etc/passwd file

at the moment I've got

for user in $( cat /etc/passwd )
do
...
done

inside the loop I would like to split $user = "username:uid:etc:etc" into $username, $uid., $gid, $etc...

Any suggestions?

Many Thanks
Murray
 
Old 09-21-2004, 03:20 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
Here's my solution:
Code:
cat /etc/passwd | while IFS=: read Name UnusedByNT Uid Gid RealName HomePath ShellPath; do
    echo "name:$Name uid:$Uid gid:$Gid home:$HomePath shell:$ShellPath"
done
Note, however, that this example is based on the Cygwin passwd file, which is slightly different from that of Unix/Linux. Just adapt.

Yves.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse String in a Bash script jimwelc Linux - Newbie 8 11-09-2012 07:47 AM
How to replace string pattern with multi-line text in bash script? brumela Linux - Newbie 6 04-21-2011 06:56 AM
escape string in bash script so it can be used in command line BuckRogers01 Linux - Software 15 08-12-2010 09:38 AM
Simple bash script help, grabbing part of a string colabus Linux - Newbie 3 04-25-2005 09:42 AM
bash-script: output text between two ocurrences of a specific string isl01jbe Programming 1 06-17-2004 02:36 PM


All times are GMT -5. The time now is 09:48 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration