LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I extract the group names from the id output? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-extract-the-group-names-from-the-id-output-4175711677/)

noob555 05-04-2022 02:24 PM

How can I extract the group names from the id output?
 
Hello all,

I belong to these groups in my linux os.

Code:

$ id
uid=1000(davevlz) gid=1000(davevlz) groups=1000(davevlz),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),115(lpadmin),135(sambashare),999(vboxusers)

How can I extract the group names and use a comma as a delimiter to look like this below:

davevlz,davevlz,davevlz,adm,cdrom,sudo,dip,plugdev,lpadmin,sambashare,vboxusers

Thanks in advance

boughtonp 05-04-2022 02:35 PM


 
Use "groups" instead of "id"

If you then need to change delimiter from space, "tr" is probably the simplest option.


noob555 05-04-2022 02:47 PM

Quote:

Originally Posted by boughtonp (Post 6350756)
Use "groups" instead of "id"

If you then need to change delimiter from space, "tr" is probably the simplest option.


Code:

$ groups | tr " " ","
davevlz,adm,cdrom,sudo,dip,plugdev,lpadmin,sambashare,vboxusers

Thanks a bunch :) :thumbsup: :) it works!!!


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