1. Home
  2. Docs
  3. Beginning UNIX on Raven
  4. Answers
  5. Answers to redirection exercises

Answers to redirection exercises

1. Using head and tail display the first chorus of our lyrics.

head -n 21 americanpie.txt | tail -n 5

2.. Output the first chorus to a file called chorus.txt

head -n 21 americanpie.txt | tail -n 5 > chorus.txt

3. Repeat this command, but also make the output appear on the screen.

head -n 21 americanpie.txt | tail -n 5 | tee chorus.txt

4. Repeat the above, but put a title on the chorus “American Pie chorus” and output the file to chorus2.txt

echo “american pie chorus” > chorus2.txt

head -n 21 americanpie.txt | tail -n 5 >> chorus2.txt