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:
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: 2. Relevant commands, code, scripts, algorithms: 3. The attempts at a solution (include all code and scripts): 4. 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
Last edited by methyl; 05-04-2012 at 07:47 PM..
Reason: Please use code tags ; correct some typos for readability
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:
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.
@methyl:
Arch Linux.
Last edited by methyl; 05-04-2012 at 07:59 PM..
Reason: Separate commands from text with icode tags.
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.
Hi Team,
Can anyone help me here:
I have to access server logs via putty and these logs file is a trailing file (continously updating) with ERROR and WARNINGS... I need to know if I can pull this trailing file to a local drive so that I can do some higlighting on some keywords through Notepad... (13 Replies)
Hi,
I want to do file format using awk script, for that i wan to use 'tail'. Here is the scenario. I will be having set of files in a directory. Those files i need to write to another directory with same file name, but while writing the file to out directory, i need to write the last line as... (3 Replies)
Hi does anyone know how to create a file using the tail command? My book has this file I need to create and it says to use the tail command and that it is possible but I have no idea. Thanks. (4 Replies)
Hi,
In my home directory, there are so many files. i tried to get the lastly created file by following command.
file=`ls -lrt MXOfiles* | tail -1`
As there are so many files, it displays
"$ : 0403-027 The parameter list is too long."
Can someone tell me how can i get the recent file... (1 Reply)
Hi Dears,
I am using AWK script to monitor some log files. My awk will get the input from the output of tail -f LOGFILE. (tail -f LOGFILE | myawkanalyzer)
My doubt is, How can I notify, if I didn't get any output from the tail -f command. i.e) Log file stuck for some reason. I want to display... (1 Reply)
Hi All,
My query seems to be silly but Iam unable to find where the exact problem lies.
I have a script to unzip set of files
here is the script
#!/bin/ksh
Count=`cat /home/gaddamja/Tempfile | wc -l`
while
do
Filename=`cat /home/gaddamja/Tempfile |tail -$Count | head -1`
cd... (7 Replies)
HI i have to copy the last 5000 lines form a log file and copy the same in the same file .overwriting the same log file.
ex: tail -5000 testfile1 > testfile2
cat testfile2
mv tesftfile2 testfile1
will produce the correct result.but i want to have this done in one line???? (4 Replies)
I was wondering how can I do this
I have file myfile.txt
wc -l is: 5 000 000
I have to remove first 1 000 000 lines from header..
I tryed with tail -4000000 myfile.txt>newfile.txt
but it does not work...
any help?? (2 Replies)
Hi ,
I have found a interesting thing about tail command:
when I tried to use 'tail -1 *' to look at every file with the current derectory, I only got one line of result of one file.
But if I use 'head -1 *', I would get multiple lines.
Is there a way to do get multiple lines with 'tail -1 *'... (3 Replies)
I am trying to using pipe (|) with ! (not) operator to list all the other files except the latest two and I am using the following command.
$ ls -ltr *.lst|!(tail -2)
ksh: 20050211180252.lst: cannot execute
but it is trying to execute the file returned by tail -2. I am able to do that in 4... (8 Replies)