Unix Workout: Unix Pipelines and More

By now you already have some experience with the Unix shell. So some of the material covered in the following three tutorial will not be new to you:

  • Tutorial 1: Listing files and directories. Making and changing directories.

  • Tutorial 2: Copying, moving and deleting files. Displaying the contents of a file on the screen

  • Tutorial 3: Redirecting output and using pipelines.

Read through these tutorial and learn by doing what is new. For example, the grep command in Tutorial 2 and Unix pipelines in Tutorial 3. In the following entertaining video Brian Kernighan (one of the original Unix inventors) talks about the grep command:

Quiz

From the tutorial you know that

1
grep foo some_file.txt

prints all lines of some_file.txt that contain the string foo. But actually the grep command is much more powerful! You also can print out all lines that match a so called regular expression. For example

1
grep "^[a-zA-Z]*(" some_file.txt

prints all lines that begin with a word that is followed by an open parenthesis. Hereby the word is described as follows:

  • It only has characters a to z or A to Z and

  • it can have zero or arbitrary many characters.

Extract from the file /home/numerik/pub/ss22/session03/lexer.c on theon all the lines that begin with a word as described above. Sort these lines alphabetically and save this sorted list in a file list.txt. Of course this can be done with a one-line command. Write this command into a file cmd.txt

submit hpc quiz03 list.txt cmd.txt