===================================== Unix Workout: Unix Pipelines and More [TOC] ===================================== 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: ---- VIDEO ------------------------------ https://www.youtube.com/embed/NTfOnGZUZDk ----------------------------------------- Quiz ==== From the tutorial you know that ---- CODE ---------------------------------- 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 ---- CODE ---------------------------------- 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. ---- BOX ----------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- :links: Tutorial 1 -> http://www.ee.surrey.ac.uk/Teaching/Unix/unix1.html Tutorial 2 -> http://www.ee.surrey.ac.uk/Teaching/Unix/unix2.html Tutorial 3 -> http://www.ee.surrey.ac.uk/Teaching/Unix/unix3.html Brian Kernighan -> https://en.wikipedia.org/wiki/Brian_Kernighan regular expression -> https://en.wikipedia.org/wiki/Regular_expression