## Pipes

 1. It will be a few more weeks before we get to describe pipes in the
    lectures. For now, we can consider them to be magical.
 2. The way we will use pipes is to connect programs together in a simple way.
 3. If you remember, it was mentioned earlier that you can run a file through
    a pager like this:
    
        $ cat file.txt | less
    
    This is a pipe. The entire command is sometimes called a ‘pipeline’.

 4. Pipes take output of one command and present them as input to another.
    Most UNIX utilities are designed to work well with pipes.
 5. If you want to count all the lines in all the text files in your current
    directory, you can say:
    
        $ cat *.txt | wc -l

 6. One useful command to use in pipelines is ‹cut› (try ‹man cut›). You can
    also try the following command:
     
        $ echo hello:world | cut -d: -f2
    
    The switch ‹-d› gives the delimiter, ‹-f› asks for a particular delimited
    field. You can use ranges too, like ‹-f 2-4›.

 7. Pipelines are often used for working with text. A very powerful tool is
    ‹grep›. It allows you to use «regular expressions» to select a subset of
    lines that match a pattern. We will only use it in a simpler version,
    without regular expressions for now. This variant is called ‹fgrep› (where
    ‹f› stands for ‘fixed’). To print all lines from ‹file.txt› that contain
    the word ‹frob›, you could run:
    
        $ fgrep frob file.txt
    
    Or with pipes:
    
        $ cat file.txt | fgrep frob

 8. I will show you one last command for today, and that is ‹sort›. This is
    also quite useful in pipelines. It rearranges input lines into alphabetical
    order.

To practice working with pipes, check out ‹3.txt›.
