Home > Back-end >  execute bash expression without temporary file in bash native way
execute bash expression without temporary file in bash native way

Time:06-22

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

CodePudding user response:

It seems like you want the list the additional groups of a user:

Is so then you could reduce it to:

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

CodePudding user response:

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}'
  • Related