Search code examples
windowsbashoutputglobalrestriction

Bash output restrictions


I need to determine if a user is in a certain group.

I am currently using this line in command prompt.

whoami /groups > Desktop\output.txt 

Unfortunately it is giving a lot of information I do not want.

Is there a way to restrict the command to only output Group names where the Type = Group?

Thanks,

-Childish

Example of my output (Just a template)

Group Name                              Type             SID                                              Attributes                                                     
======================================= ================ ================================================ ===============================================================
Everyone                                Well-known group #1                                          Mandatory group, Enabled by default, Enabled group      
Pizza                                   Group            #2                                          Mandatory group, Enabled by default, Enabled group

I gave 2 "examples" above. In this situation, I would only want the Group name "pizza" out of the output.


Solution

  • I'm not familiar with bash on windows, although in most versions you could pipe your output to awk:

    whoami /groups | awk '$1 == "Pizza"' > Desktop\output.txt
    

    This should only output lines which contain Pizza in column one. Another example by "Type":

    whoami /groups | awk '$2 == "Group"' > Desktop\output.txt
    

    This should only output lines which contain Group in column two.

    Output:

    Pizza                                   Group            #2                                          Mandatory group, Enabled by default, Enabled group