Sorting the passwd file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

Sort the file /etc/passwd using the fourth field (group ID) as the primary sort, and the third field (user ID), as the secondary sort and send the output to sortedpasswd and also displaying the output on the monitor in one command line.

  1. Relevant commands, code, scripts, algorithms:

sort -t: -k4,4 -k3,3 /etc/passwd

  1. The attempts at a solution (include all code and scripts):

I am able to sort the file and redirect it to a new file "sortedpasswd", the problem I am running into is being able to do both. I've tried piping it through cat command and if i sort -t: -k4,4, -k3,3 > sortedpasswd, all it does is send it to a file without showing the results on the screen. Not sure how to get this done in one command line. vi or cat the results of the file would work for me, but the question appears to be doing it all in one line.

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Hagerstown Community College, Hagerstown, MD, USA Professor Trudy Gift IST-109 Introduction to Unix/Linux. This is a test question. For the record, (not sure if this excludes me from being able to ask it) All tests in this course are "take home" and using resources other than the text book, including the internet is allowed and encouraged.
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Edit: I dont understand what you mean about "link to course" I am told I cannot post a url in a thread without "5 points". However all class and instructor information is correct and verifiable to the best of my abilities and understanding.

Solution to your 3rd question would be using

tee

command

sort -t: -k4,4, -k3,3 |tee outputfile
1 Like

Or even:

sort -t: -k4,4, -k3,3 /etc/passwd |tee outputfile

Thanks Guys! By George, it works! (Who is George anyway?)