Practicum - week 11

Introductory remarks:

When you have a task to solve, first read it through very-very carefully (a lot of mistakes are done because people have not read my text carefully enough). Then decompose the problem, and don't try to solve the whole task at once. Don't be upset if you do not know how to solve it immediately. Play around with the problem, and try to solve a simplified version of it: maybe this playing around with the problem gives you ideas. Finding how to decompose usufully a task is usually already half way to the solution.

Therefore, first try to solve one part of it, and check whether you have done it. Only then try to go further to solve the second part of the task, and so on. At each step, check whether your solution indeed does what you expect it to do. So, when you build a pipe-line for instance, first check the outcome of the first element, then check what the second element does in itself, then check the outcome of the first two elements together, and so on. If something goes wrong, go back, and check each element seperately.

Another tip: before trying to solve the assignments, read through the examples on the web-site of the lecture and your own lecture notes. Furthermore, it is not enough to read them through. You need to think them through, and to try them out on the computer. If you do not understand fully an example, decompose it: try out what the first part of the pipe-line does, and what the second part does. What happens if you do not use a given option of some command, or if you leave out one element of a pipe-line. Try to really understand what you do!

Unless otherwise specified, you need to email me one pipe-line as the solution of each assignments. If you have just partial results, and you have not solved the whole problem, still send me what you have.


Without using the command 'ls' and its options, get a list ordered in the reverse alphabetical order of the file names in your directory. (There are very different solutions!)

(2 points)


  1. Think of wildcards and of the easiest building blocks in the "Lego-game"
  2. Think of the building blocks that can help you in ordering a text, reversing its order, etc.
  3. Check the web-site of the lecture.
  4. Use 'more' or 'less' to check the content of a file. You can use also 'cat', but it is not useful if the file is too long (why?). You can use also 'pico' or 'xemacs' or another text editor, but if you do not plan to edit it, 'more' or 'less' are more handy. You can use 'more' or 'less' at the end of a pipe line to see the result of that pipe line, if it is too long.
  5. Decompose the task: don't try to solve the whole assignment at once, but first get the list of the file names, and if this is done only then try to order it and to reverse the order, etc.
  6. One of the commands learned can handle new line characters (check the web site!).
  7. If this assignment is too complex, you maybe want to go further to assignments 2-5, before you try to solve this.


From now on we will work with the Federalist Papers. For more information about this project by George Welling see:  USA project and also this site.

In the lab, you will find the files you need for the assignments under: ' /users1/birot/Federalist '.

Read the README file in this directory.

Get a list of these, and look at the content of some of them (using cat, more or less).

In fed84.txt there are many numbers. Imagine you want to hide them for some reasons (let's say because that is a secret document), so you want to put a star at the place of each digit (0-9). How would you do that?

(1 point)


Catenate (put togather as a chain) (the content of) all the files written by James Madison.

(1 point)


Count the number of characters appearing in all articles written by James Madison (the sum of the characters, together). Can you do that in one or in two commands? The command line should return just one number, and this is the number of the characters.

Send me both the command line and the result.

(1 point)


Write a command line that will return you the number of words in the file fed35.txt multiplied by the number of lines in jay2.txt.

Tip: in the case of commands that do something with a file, you have usually two ways of giving the file name to the command: either by giving the file name as an argument of the command, or by redirecting the input of that command. Try out both ways, because the outlook of the output (that you possibly want to turn into the argument of another command: do you know how to do that?) may be different in the case of the command that you need to use in this exercise.

Send me both the command line and the result.

(2 point)


Collect the headers (the first lines including the title) of all papers written by Alexander Hamilton into one file "headers". Within the same pipe-line, create a list of the words occuring in the file "headers". Save that list into the file "wordlist". Finally, still within the same pipe-line, print that wordlist on the screen that you get if you log in to the virtual terminal tty2 (CTRL+ALT+F2).

Tips: remember what I said a week ago about that the terminals are also files (also on the web site of this week's lecture), remember the command 'tty', and read the excursus on the web site of this week's lecture about woordenlijsten.

(3 points)