Home
Man
Search
Today's Posts
Register

Students must use and complete the template provided. If you do not use the template your post may be deleted! Special homework rules apply here.

Display usernames and their UIDs

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 05-27-2018
Display usernames and their UIDs

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:

Write a script that displays all usernames and their UIDs in the following fashion:
name1 uid=999
name2 uid=888
... ...

2. Relevant commands, code, scripts, algorithms:

grep, cut, id, echo, for…do…done

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

I managed to list usernames and UIDs but I can't figure out how to add "uid=" string. I've been coming back to this problem for the last two days but maybe my approach is wrong. Please, help
Since I don't have a Solaris or Linux on PC, I've tested the code on tutorialspoint/execute_ksh_online.

Code:
#!/bin/bash

sort -nr -t ':' -k3 /etc/passwd | cut -d: -f1,3

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

Vistula University, Warsaw, Poland, Matusiak Sławomir, CII4SP16CI-L18

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).
The Following User Says Thank You to baniel For This Useful Post:
dodona (05-28-2018)
# 2  
Old 05-27-2018
You could pipe your results through an awk or sed program that prepends "uid=" to the second field, or replaces a space with " uid=". You could also do this with a "while read" shell loop.
# 3  
Old 05-27-2018
From the given relevant commands I think the teacher or the course makers want to just cut one item from the passwd, process it in a for-do-done loop, and in the loop grep the item in the passwd again in order to get the second item.
But this is less efficient compared to piping the pair of items to awk or a while read loop.
The latter can directly split into variables if the field separator IFS is set accordingly. You do not even need to run cut before.
The Following User Says Thank You to MadeInGermany For This Useful Post:
dodona (05-28-2018)
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pam_krb5 UID mapping (clashing UIDs) cambridge Red Hat 0 10-19-2011 05:47 PM
UIDs in /etc/passwd file vvpotugunta Solaris 10 04-10-2009 05:20 PM
Usernames in Sudoers have # Gibby13 UNIX for Advanced & Expert Users 1 04-08-2009 12:35 PM
keep UIDs/GIDs consistent robertngo UNIX for Advanced & Expert Users 4 03-11-2009 04:00 AM
UIDs being overwritten immediately xsys2000 AIX 2 05-08-2007 02:00 PM
Valid ranges for uids for HP-UX naren_chella HP-UX 7 06-25-2006 11:22 PM
Usernames and processes most used anw68ster UNIX for Advanced & Expert Users 4 03-13-2006 02:05 PM
about UIDs, very urgent mehdi UNIX for Dummies Questions & Answers 1 09-06-2005 08:53 PM
max charachters for usernames m.szylkarski UNIX for Dummies Questions & Answers 1 02-01-2002 11:50 AM


All times are GMT -4. The time now is 10:04 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password