CS170 I/O Redirection and Lab Exercise
I/O Redirection, Pipes, and Sort
Use the Unix cal command to show
the birthmonth of the year you were born.
When you do that, use the I/O redirection operator ">" to
send the output to a file called "months".
i.e. type the following command:
cal mm yyyy > months
(Replacing mm yyyy with the the number of your
birthmonth and year.)
- Repeat that last command exactly to see what happens.
- Now use the command for this year's month of your birth
and append it to the "months" file you just created.
(Remember that the append operator is ">>".
- Use the command one more time, specifying just the
current year, (no month) and append that output to your "months" file.
To see what is in "months", you could enter
cat months, but there could be too many lines for
the screen to display at one time.
What you should do is direct the output of cat to the
input of the more command.
Use the pipe symbol "|" to do this.
i.e. cat months | more
You can type the Unix command who to see who is logged on.
How can you redirect the output of who to a file?
How can you redirect the input of sort from that file?
How would you use a pipe to combine those last 2 steps?
How would you redirect the output of the last step to another file?
You can expect questions like this on the lab test.
Use the remainder of this lab period to review the material from last
week's lab and to complete any parts of that lab exercise
that you did not have time for.
Copyright: Department of Computer Science, University of Regina.