Main index

Introducing UNIX and Linux


Overview
Using filters
      Collating sequence
      Character classes
Character-to-character transformation
Selecting lines by content
      Regular expressions
      Basic regular expressions
      Extended regular expressions
      Grep
Stream editor
      Sed addresses
Splitting a file according to context
Choosing between the three filters
More on Vi
Summary
Exercises

Exercises

  1. Write a filter to extract from /usr/dict/words all words containing all five vowels in alphabetical order.

    View solution

  2. A utility known as rot13 is a very simple encryption mechanism which replaces every letter by the letter 13 further on (or previous to it) in the alphabet. Thus

    The quick brown fox jumped over the lazy dog
    
    would be changed to
    Gur dhvpx oebja sbk whzcrq bire gur ynml qbt
    

    Write a script to encrypt standard input using the rot13 algorithm.

  3. List the names of all files (excluding directories) in the current directory which contain the string program (or some other string).

    View solution

  4. The file /etc/group contains lines of the form

    group-name:GID:list-of-members

    For instance, a line defining group ateam, with group ID 99, and consisting of users chris, jo and sam, would be

    ateam:99:chris,jo,sam
    

    Write a script to list the names of all the groups of which jo is a member.

  5. Write a filter, numbers, which considers its input as consisting of whole numbers (containing only digits), together with other text, and displays a list of those numbers, one per line, sorted into numerical order with duplicates removed, so:

    $ numbers <<END
    1st Blankshire Bank Ltd.,
    17-19 High Street,
    Anytown,
    Blanks.,
    AN1 4GQ.
    END

    1
    4
    17
    19

    View solution

  6. How many words in /usr/dict/words contain at least three vowels?

  7. Split the file /usr/dict/words into two halves, the first containing all words up to (but not including) middle, the second containing the rest.

    View solution


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck