Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
The problem statement, all variables and given/known data:
Devise a chain of filters using some or all of the following programs pr, cut, cat, tail to
display a numbered list of last (in the order of appearance) 7 entries from /etc/passwd file.
Each entry of the list must contain 4 fields: login name, numerical user ID, numerical
group ID, and user home directory separated by ---. For example:
The attempts at a solution (include all code and scripts):
cut | pr -tn | etc/passwd tail - 7
Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Kennesaw State Univ. Atlanta GA, USA DR. Shah CSCI 3100
Personally I can't see a way of achieving the required result with just standard unix versions of tail/pr/cut/cat . Other posters may have better ideas. Maybe you have a non-unix Operating System with extended versions of these standard commands?
To get your pipeline started (and to avoid any code which might overwrite the /etc/passwd file!), let's simplify the problem by reading only the last 7 lines of /etc/passwd and outputting only the fields we require:
tail -7 /etc/passwd | cut -d':' -f1,3,4,6
The output is however still separated with colon characters.
You now need to build the pipeline to format the output and number the lines.
Avoiding awk and sed programs which will no doubt come up later on your course, personally I'd still need a unix command like printf (or maybe tr ?) to sort out the colon characters).
Numbering the lines could be achieved with something like pr -n1 -t or perhaps just cat -n .
Again the unix printf command would be really useful for sorting out the final format including prettifying the output with hyphen characters.
Footnote: If the tail/pr/cut/cat is just a hint not a rule and you are allowed to set up a while read loop and use the echo command and use Shell arithmetic to set up a simple record counter ... it becomes much easier.
Well worth querying with your lecturer if you are allowed to use commands and techniques already taught ... as well as a selection from the suggested commands.
Hi bieri, thank you for your reply. Can you explain step by step how you came to that command? I'm just trying to get a better understanding of the process involved in using these commands instead of just getting the answer.
tail -7 /etc/passwd ---> Get last seven lines from file /etc/passwd cut -d: --output-delimiter=--- -f1,3-4,7 ---> Split line with colon, select fields 1, 3, 4 and 7, and print them separated by '---' pr -tn --indent=2 ---> You had used it in your attempt: omit header, print line number and the indent was an attempt to print numbers near the text.
Thank you @birei. All we need to know now is whether @hbell221 has an advanced Linux ... not unix. Most of the course posters we see here are being taught Bourne Shell on unix systems.
The operating system on which you run the utilities and where those data files are stored is Linux. You are using putty on a Windows system to get there, but that is not relevant here.