Week 01 Tutorial Questions

Objectives

    • What is your tutor's name and e-mail?
    • How long have they been at UNSW?
    • What are they studying?
    • Do they have a pet?
    • What is 1 interesting thing about them?

    • What are your class mates's names,
    • What are they each studying,
    • What is 1 interesting thing about each of them?
  1. What is an operating system?

  2. What operating systems are being used in your house/tutorial room?

  3. What operating system(s) do CSE lab computers run?

  4. Write a regex to match:

    1. C preprocessor commands in a C program source file.
    2. All the lines in a C program except preprocessor commands.
    3. All lines in a C program with trailing white space (one or more white space at the end of line).
    4. The names "Barry", "Harry", "Larry" and "Parry".
    5. A string containing the word "hello" followed, some time later, by the word "world".
    6. The word "calendar" and mis-spellings where 'a' is replaced with 'e' or vice-versa.
    7. A list of positive integers separated by commas, e.g. 2,4,8,16,32
    8. A C string whose last character is newline.
  5. When should you use:

    • fgrep/grep -F

    • grep/grep -G

    • egrep/grep -E

    • pgrep/grep -P

  6. grep takes many options (see the manual page for grep(1)).

            man 1 grep
        

    Give 3 (or more) simple/important options grep takes and explain what they do.

  7. Why does this command seem to be taking a long time to run:

            grep -E hello
        
  8. Why won't this command work:

            grep -E int main program.c
        
  9. Give five reasons why this attempt to search a file for HTML paragraph and break tags may fail.

            grep <p>|<br> /tmp/index.html
        

    Give a grep command that will work.

  10. For each of the regular expression below indicate how many different strings the pattern matches and give some example of the strings it matches.
    If possible these example should include the shortest string and the longest string.

    1.                 Perl
                  
    2.                 Pe*r*l
                  
    3.                 Full-stop.
                  
    4.                 [1-9][0-9][0-9][0-9]
                  
    5.                 I (love|hate) programming in (Perl|Python) and (Java|C)
                  
  11. This regular expression [0-9]*.[0-9]* is intended to match floating point numbers such as '42.5'
    Is it appropriate?

  12. What does the command grep -Ev . print and why?

    Give an equivalent grep -E command with no options,
    in other words: without the -v.

  13. Write a grep -E command which will print any lines in a file ips.txt containing an IP addresses in the range 129.94.172.1 to 129.94.172.25

  14. For each of the scenarios below

    • give a regular expression to match this class of strings
    • describe the strings being matched using an English sentence

    In the examples, the expected matches are highlighted in bold.

    1. encrypted password fields (including the surrounding colons) in a Unix password file entry, e.g.
      root:ZHolHAHZw8As2:0:0:root:/root:/bin/bash
      jas:nJz3ru5a/44Ko:100:100:John Shepherd:/home/jas:/bin/zsh
      andrewt:ugGYU6GUJyug2:101:101:Andrew Taylor:/home/jas:/bin/dash
              
    2. positive real numbers at the start of a line (using normal fixed-point notation for reals, not the kind of scientific notation you find in programming languages), e.g.

      3.141 value of Pi
      90.57 maximum hits/sec
      half of the time, life is silly
      0.05% is the legal limit
      42 - the meaning of life
      this 1.333 is not at the start
              
    3. Names as represented in this file containing details of tute/lab enrolments:

      2134389|Wang, Duved Seo Ken         |fri15-spoons|
      2139656|Undirwaad, Giaffriy Jumis   |tue13-kazoo|
      2154877|Ng, Hinry                   |tue17-kazoo|
      2174328|Zhung, Yung                 |thu17-spoons|
      2234136|Hso, Men-Tsun               |tue09-harp|
      2254148|Khorme, Saneu               |tue09-harp|
      2329667|Mahsin, Zumel               |tue17-kazoo|
      2334348|Trun, Toyin Hong Recky      |mon11-leaf|
      2336212|Sopuvunechyunant, Sopuchue  |mon11-leaf|
      2344749|Chung, Wue Sun              |fri09-harp|
      ...
              
    4. Names as above, but without the trailing spaces (difficult).
      Hint: what are given names composed of, and how many of these things can there be?