I have to take user input of there UID then use it to reference the /etc/passwd directory and sort the data by first name and display only username,firstname,lastname in that order. The problem i'm having is sorting the output. if i use a command like
cat /etc/passwd |grep $id_prefix | sort | cut -d: -f1,5
The output sorts by username and displays in a lastname, firstname order. I know I could change the command to something like.
cat /etc/passwd |grep $id_prefix | sort | cut -d: -f5 | sed 's/\([^ ]*\)[ ][ ]*\([^ ]*\)/\2 \1/'
Then I will get the output sorted and cut how I want it but it will not contain FIELD1, the usernames. How would I write this to correctly display all the fields I need and also sort them?