how to display users under a group in a line for each user in Linux bash

Issue

Currently when i run a grep command on a visitors group that i had created

grep visitors:x:1011: /etc/group

This is a sample result of the above command, as the actual result is too long.

visitors:x:1011:ellipsiscoterie,magnetcommonest,wizardmeans,beakskeletal,lemonwellmade,ralphpaperclips etc..

How do i display the above result as show below (without visitors:x:1101 and seperating the commas), as i have difficulty doing so.

ellipsiscoterie
magnetcommonest
wizardmeans
beakskeletal
lemonwellmade
ralphpaperclips

Solution

I suggest using sed instead of grep

sed -n -e 's/^visitors\:x\:1011\://p' /etc/group | tr ',' '\n'

UPD: detailed explain of sed part is here. tr examples you can find here

Answered By – Pavel Sapezhka

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published