LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 02-20-2013, 02:16 AM   #1
nitya
LQ Newbie
 
Registered: Feb 2013
Location: India
Distribution: RedHat, Cent, Fedora, Ubuntu
Posts: 21

Rep: Reputation: Disabled
bash to print words/lines vertically


Hi All,
How can I print the below supplementary groups vertically,
Code:
$ id -Gn nitya
Admin apache cvs
The output I am expecting as
Code:
Admin
apache
cvs
Thanks in advance for your kind help.
 
Old 02-20-2013, 02:29 AM   #2
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
Hi nitya,
Quote:
id -Gn nitya | perl -pi -w -e "s/\ /`echo "\n"`/g"
Probably you can use the above command. However there will be other commands which can do the required work in more easiest way. You can wait for other people comments here if you want.
 
2 members found this post helpful.
Old 02-20-2013, 02:41 AM   #3
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 275Reputation: 275Reputation: 275
Code:
for i in $(id -Gn nitya) ;do echo $i; done
 
2 members found this post helpful.
Old 02-20-2013, 02:43 AM   #4
nitya
LQ Newbie
 
Registered: Feb 2013
Location: India
Distribution: RedHat, Cent, Fedora, Ubuntu
Posts: 21

Original Poster
Rep: Reputation: Disabled
Dear RaviTezu,
Code:
id -Gn nitya | perl -pi -w -e "s/\ /`echo "\n"`/g"
Excellent, The above command worked great, But since I don't know about perl I couldn't understand "perl -pi -w -e "s/\ /`echo "\n"`/g"", if you possible could you please expain the perl arguments.
Thank you very much.
 
Old 02-20-2013, 02:48 AM   #5
nitya
LQ Newbie
 
Registered: Feb 2013
Location: India
Distribution: RedHat, Cent, Fedora, Ubuntu
Posts: 21

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kooru View Post
Code:
for i in $(id -Gn nitya) ;do echo $i; done
Dear kooru, Excellent. this is what I was expecting. You both solved my problem.
Once again thank you all.
 
Old 02-20-2013, 06:04 AM   #6
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
Have a look at perl man page & Here
 
Old 02-20-2013, 06:19 AM   #7
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
id -Gn nitya | xargs -n1
 
  


Reply



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
[SOLVED] get two/more specific words on a line and print next few lines Kashif_Bash Programming 11 04-26-2012 12:15 AM
[SOLVED] bash print only found words newbie0101 Linux - Software 5 01-13-2012 03:09 AM
bash: Can I print new information on allready printed lines? Romanus81 Programming 1 11-13-2008 02:12 PM
how many lines and words (bash) sharapchi Programming 4 12-15-2006 12:45 PM
Bash - How to make For read lines instead of words in a list ? landuchi Programming 10 02-15-2006 01:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:19 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
Open Source Consulting | Domain Registration