1

I have worked code

id | tr -s ',' '\n' > output1 && tail -n $( expr $(cat output1 | wc -l) - 1 ) output1

but i want it without temporary file. thank you

3 Answers3

0

If the objective is to skip the 1st line of output from the id | tr command pair:

$ id | tr -s ',' '\n' | tail -n +2

# or

$ id | tr -s ',' '\n' | awk 'FNR>1'

Or eliminating the tr call and printing everything after the 1st ,:

$ id | awk -F, '{for (i=2;i<=NF;i++) print $i}'
markp-fuso
  • 28,790
  • 4
  • 16
  • 36
0

An arguably more "bash native" way to do this is:

IFS=, read -r -a id_parts  < <(id)
printf '%s\n' "${id_parts[@]:1}"
pjh
  • 6,388
  • 2
  • 16
  • 17
0

If you want get all user-groups and for a better output

awk '
   NR==1{split($0,ids); next} 
   {split($0,names)}
   END{
    #for(i in ids) printf "%d(%s)\n", ids[i], names[i]
    for(i in ids) printf "%5d ==> %s\n", ids[i], names[i]
}' <(id -G) <(id -nG)

1000 ==> ufopilot
   4 ==> adm
  27 ==> sudo
 139 ==> docker
ufopilot
  • 3,269
  • 2
  • 10
  • 12