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
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
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}'
An arguably more "bash native" way to do this is:
IFS=, read -r -a id_parts < <(id)
printf '%s\n' "${id_parts[@]:1}"
IFS=, read -r -a id_parts ...
.< <(id)
.printf '%s\n' "${id_parts[@]:1}"
.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