Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

Rep: Reputation: 15
Bash Script String Splitting

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 )

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

Any suggestions?

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

Rep: Reputation: 63
Here's my solution:
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"
Note, however, that this example is based on the Cygwin passwd file, which is slightly different from that of Unix/Linux. Just adapt.



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 > Forums > Linux Forums > Linux - Newbie

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

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