Question
Instructions: Part I : Build a user reference data file with the usernames and full names by extracting the necessary information from the /etc/passwd file.
Instructions:
Part I: Build a user reference data file with the usernames and full names by extracting the necessary information from the /etc/passwd file.
- Sort the /etc/passwd and get line 100-110 of that file. Use the cut command to extract the username from /etc/passwd. Save the result file as ids.
- Create another file called names which contain full names of line 100-110 of sorted /etc/passwd in a similar way.
- Use the paste command to combine the two files, ids and names, together side-by-side as shown below, redirect the output to a file called users.ref. For ease of processing, separate the two fields with a space. If there is any , in the file, use an editor to get rid of them. The final version of users.ref should look like the following format:
sally.black Sally Black jane.smith Jane Smith lily.brown Lily Brown
Before you continue with Part II, it is a good idea to save a copy of users.ref. You will know why when you accidentally erase the contents of the data file.
Part II:
For the following steps, write shell programs that use command line arguments as input to the shell program. Do not prompt the user for input from the keyboard! Note: Most of these shell programs need to be only 1 or 2 lines long.
- Write a shell program called list to display all the usernames and full names in the users.ref file. The information should be displayed in alphabetical order by student's last name (not by username). Save the list shell program in your lab7 directory.
- Write a shell program called find to locate an existing record in users.ref and display the student's username and full name on the screen. The search should not be case sensitive. This shell program should allow the user to specify either a student's username or their full name. Save the find shell program in the lab7 directory.
$ find "lily.brown" or $ find 'Lily Brown'
- Did you encounter any problems in the previous step? If so, what were they and how did you resolve them? Include a note describing the problems and solutions in a file called lab7.notes.
- Write a shell program called remove which deletes a student's entry from your users.ref file. Similar to find, the user should be able to specify the student to be removed by their username or their full name. Save the remove shell program in lab7. (hint: grep has an option "-v". Go check it out!)
- Write a shell program called add to add a new username and full student's name to your users.ref file. Your program should be used in the following manner (hint: echo hello >> file):
$ add woody.brown 'Woody Brown'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started