Lesson 4 Practice
For today's practice, we are going to embark on a Unix treasure hunt created by the Sanders Lab at the University of California San Francisco. Note: the treasure hunt materials can be obtained directly from the Sanders lab code repository linked above.
To begin create a directory called treasure_hunt
in your home directory and run the perl script in /data/Practice_Sessions/Practice_L4
from the treasure_hunt
directory.
Solution
mkdir treasure_hunt
cd treasure_hunt
perl /data/Practice_Sessions/Practice_L4/treasureHunt_v2.pl
ls -l
Read the first clue and begin.
Recommendation: Create an environment variable to store the path to the treasure hunt directory to facilitate movement through the directory.
Solution
THUNT=`pwd`
echo $THUNT
When you have found the treasure, answer or do the following:
-
How many words are in the last line of the file containing the teasure?
Solution
2. Save the last line to a new file calledtail -n 1 openTheBox.txt | wc -w
finallyfinished.txt
without copying and pasting.Solution
tail -n 1 openTheBox.txt > finallyfinished.txt
3. Now append the first line to the same file that you just saved the last line.Solution
head -n 1 openTheBox.txt >> finallyfinished.txt
Congratulations! You have found the treasure and have gained some useful unix practice throughout your hunt.