The following are some fun UNIX exercises to utilize to sharpen your skill set.
The boss has asked you to show your new UNIX intern how to
format a report in the following manner – since these are the kinds of reports
the intern will be creating all summer long:
1) Output the word count of a report1 then append it to the
existing report2:
Answer: wc
–l report1 >> report2
2) Using awk show how to extract column 5 (the file size)
from the output of ls -l
Answer: ls
–l | awk ‘{print $5}’
3) Using sed show how to substitute a change in words globally taking the input from a file
Answer: sed
–e ‘s/platform/computer/g’ < file.txt
4) Using tr convert a file from uppercase to lowercase
Answer: tr
‘A-Z’ ‘a-z’ < file.txt
5) Using grep to search for text in a file at the beginning
of a line that starts with the word the
Answer: grep
‘^The’ the.sh
6) Using grep to search for text in a file at the end of a
line with the word of
Answer:
grep ‘of$’ the.sh
7) Use grep to search for a dollar sign in a file
Answer:
grep ‘.$’ the.sh