Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 04-13-2004, 11:55 AM   #1
Registered: May 2003
Posts: 256

Rep: Reputation: 30
Question Converting a string from /etc/passwd

Using Shell commands, ( I.e. grep, sed, awk ), how do I make the following:

rliguori:x:501:213:Robert Liguori:/home/rliguori:/usr/bin/sh

look like this:

rliguori 501 Robert Liguori
Old 04-13-2004, 01:00 PM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Try this:
echo "rliguori:x:501:213:Robert Liguori:/home/rliguori:/usr/bin/sh" | awk --field-separator=":" {'print $1" "$3" "$5'}
Old 04-13-2004, 01:26 PM   #3
Registered: Aug 2003
Location: New Delhi, India
Distribution: RHEL AS 3/4, Windows XP
Posts: 546

Rep: Reputation: 31
Well, I know you wanna get this done using grep, sed and awk...but here's another way of getting the same output..

cat /etc/passwd | grep ^rliguori | tr ':' ' ' | cut -d ' ' -f 1, 3, 5


Old 04-13-2004, 02:32 PM   #4
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Originally posted by coolamit78
Well, I know you wanna get this done using grep, sed and awk...but here's another way of getting the same output..

cat /etc/passwd | grep ^rliguori | tr ':' ' ' | cut -d ' ' -f 1, 3, 5
But you ARE using grep ;)



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
Converting qmail from /etc/passwd to LDAP k41184 Linux - Security 1 11-12-2005 03:57 AM
converting a int to string irfanhab Programming 6 07-30-2005 09:40 PM
converting string to asterisks pantera Programming 2 09-13-2004 01:27 PM
C# trouble converting from string to double. exodist Programming 2 02-23-2004 11:38 PM
Converting a paragraph into a one-line string ganninu Linux - General 4 12-03-2003 07:50 AM

All times are GMT -5. The time now is 05:39 PM.

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