LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash to print words/lines vertically (https://www.linuxquestions.org/questions/linux-newbie-8/bash-to-print-words-lines-vertically-4175450909/)

nitya 02-20-2013 02:16 AM

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.

RaviTezu 02-20-2013 02:29 AM

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.

kooru 02-20-2013 02:41 AM

Code:

for i in $(id -Gn nitya) ;do echo $i; done

nitya 02-20-2013 02:43 AM

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.

nitya 02-20-2013 02:48 AM

Quote:

Originally Posted by kooru (Post 4895773)
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.

RaviTezu 02-20-2013 06:04 AM

Have a look at perl man page & Here

linosaurusroot 02-20-2013 06:19 AM

id -Gn nitya | xargs -n1


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