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-30-2010, 11:44 PM   #1
henrtm05
LQ Newbie
 
Registered: Sep 2010
Posts: 11

Rep: Reputation: 0
spacing


I am using the following command.

commas=`grep $uname /etc/group | cut -d: -f1 | tr [:space:] ,| cut -d, -f1-`

$uname is username

I get results like root,otherguy,newguy

I would like it to look like root, otherguy, newguy

I figured out how to remove the comma from the last one, but I am unable to figure out how to have a space between the commas which I would like to have.

This is for Linux Centos

Please Help

Last edited by henrtm05; 10-01-2010 at 12:14 AM.
 
Old 10-01-2010, 12:01 AM   #2
Tinkster
Moderator
 
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
[edit]misread requirement[/edit]

Cheers,
Tink

Last edited by Tinkster; 10-01-2010 at 12:11 AM.
 
Old 10-01-2010, 12:03 AM   #3
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 45
Code:
echo "root,otherguy,newguy" | sed 's/,/, /g'
 
Old 10-01-2010, 12:07 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
# awk -F":" -vu="$uname" '$1~u{print $1}' ORS=", " /etc/group
 
Old 10-01-2010, 12:13 AM   #5
Tinkster
Moderator
 
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
Quote:
Originally Posted by ghostdog74 View Post
Code:
# awk -F":" -vu="$uname" '$1~u{print $1}' ORS=", " /etc/group
Almost ...
Code:
# awk -F":" -vu="$uname" '$0~u{print $1}' ORS=", " /etc/group

Last edited by Tinkster; 10-01-2010 at 12:19 AM.
 
Old 10-01-2010, 12:18 AM   #6
henrtm05
LQ Newbie
 
Registered: Sep 2010
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks for the help, I am trying to do this with the simplest commands possible, such as grep and cut is there a simpler way to do it. For example using only the cut command?
 
Old 10-01-2010, 12:49 AM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by henrtm05 View Post
Thanks for the help, I am trying to do this with the simplest commands possible, such as grep and cut is there a simpler way to do it. For example using only the cut command?
using awk is the simplest(and fastest) way, without invoking extra processes

Last edited by ghostdog74; 10-01-2010 at 12:52 AM.
 
Old 10-01-2010, 12:51 AM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Tinkster View Post
Almost ...
Code:
# awk -F":" -vu="$uname" '$0~u{print $1}' ORS=", " /etc/group
nah, still sticking to $1, since the first field is user name. There's no need to check the whole line.
 
Old 10-01-2010, 04:06 PM   #9
Tinkster
Moderator
 
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
Quote:
Originally Posted by ghostdog74 View Post
nah, still sticking to $1, since the first field is user name. There's no need to check the whole line.
If you look at the initial approach he's checking the first
field of the group file lines where the user is present on
the line, and print those.
If he just wanted the ONE unique group for a user he'd
be much better of to just do a lookup on the users gid,
and it would be pointless to make an effort to separate
the groups w/ commas, because there'd (on a normal
system, anyway) only be one group for each user.



Cheers,
Tink
 
Old 10-01-2010, 06:15 PM   #10
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Tinkster View Post
If you look at the initial approach he's checking the first
field of the group file lines where the user is present on
the line, and print those.
well, that's what i am doing too. BUT i am not forcing the regex engine to search the whole line.
 
Old 10-01-2010, 06:19 PM   #11
Tinkster
Moderator
 
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
Quote:
Originally Posted by ghostdog74 View Post
well, that's what i am doing too. BUT i am not forcing the regex engine to search the whole line.
Ummm ... no, you're comparing the username to
the first field, which is the groupname.


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
blank spacing in Vi LinuxNewbie999 Programming 1 11-10-2006 11:10 AM
Font Spacing darkjedi8359 Mandriva 1 01-12-2005 12:37 AM
Icon Spacing. RoaCh Of DisCor Linux - Software 1 07-11-2004 06:43 PM
font spacing zeb_666 Linux - General 0 05-01-2004 10:29 AM
Character spacing in Gimp wiggywag Linux - Software 1 09-22-2003 03:36 AM


All times are GMT -5. The time now is 03:54 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