LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 04-13-2004, 12:55 PM   #1
liguorir
Member
 
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, 02:00 PM   #2
david_ross
Moderator
 
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, 02:26 PM   #3
coolamit78
Member
 
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

Regards,

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

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
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 ;)



Cheers,
Tink
 
  


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


All times are GMT -5. The time now is 06:55 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration