Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print linux group names on multiple line instead of single line output

Tags:

linux

unix

sed

yaml

I have tried getent, group command, id -Gn $user and some sed combination but I don't think I am able to achieve hence reaching out to fellow programmers.
I want to be able to print this : groups abc123
Output abc123 : devops build test design

Expected Output
groups:
- devops
- build
- test
- design

like image 313
HazeCloud Avatar asked Jan 13 '16 11:01

HazeCloud


People also ask

How do I print a group in Linux?

Using the id command The id command prints information about the specified user and its groups. If the username is omitted it shows information for the current user. To print only the names instead of the numbers use the -n option. Option -g will print only the primary group and -G all groups.


1 Answers

using bash:

for i in `groups`; do echo $i; done

using tr:

groups | tr \  \\n
like image 184
bibi Avatar answered Oct 02 '22 13:10

bibi