Q:

Sort with field separator

I'm trying to sort the /etc/passwd numerically by user id numbersb(third field) in ascending order and then send it to s4.
What command would I uses to do that? I'm on this for a while now. 

A:

Try the below code, Sort the /etc/passwd based on uid.
sort -n -t ':' -k3 /etc/passwd

A:

There is a specific command for sorting the /etc/passwd file by UID:
# pwck -s

Just to be safe, you should use this instead of generic sort if you're sorting the actual, active /etc/passwd file for your system, as pwck will handle the necessary file locking correctly. Otherwise strange things might happen if someone attempted to log in or even query some user information while you're replacing the /etc/passwd file.

