Chapter 4 Assignment
Due Wednesday October 10th
Using M.S. WORD only, type answers for questions 1 - 6 and drop it in the Chapter 4 Drop Box on OnCourse.
Questions 7, 8, 9, and Bonus Problem will be answered in the server in your/homework/chapt_4 directory.
1. Using the correct utility, write the commands that will search through a text file named search_me.txt that will:
(10 pts)
a. find all instances of the word “the” in the file and list their line numbers.
b. reverse all lines that don’t contain the word “the”
c. find every instance of the words “and” and “And”
d. find any string that starts with “ab” and ends with “ed”
2. Write one command that will find files in your home directory that have not been accessed for 30 days, zip them,
and redirect the output to a file named “changed_30_zipped.txt” (10 pts)
3. Write a sed command that will indent all the lines of a text file named [Link] and redirect the output to a file
named “ind_text.txt” (10 pts)
4. Write the linux commands to create a cronjob that will: (10 pts)
a. create a file named my_cron.cron
b. register the cronjob
c. edit my_cron.cron such that it:
[Link] a message that says “Reminder to me: call Mom!”
[Link] message will appear every Sunday, every week, every month at noon
1. Create file here:
2. Register cronjob here:
3. Command to edit cronjob here:
4. Text to edit cronjob here:
5. Write a command that will create a tarball named “tarred_up” that will tar all of the contents of your home
directory (including all sub-directories). (10 pts)
6. Write the commands that will: (10 pts)
a. backup (not tar) all of the files in the current working directory that end with .txt into a file named “cwd_bak”
b. list all of the files in in the backed-up “cwd_bak”
7. Finish the following Perl script and name it [Link]: (10 pts)
#!/usr/bin/perl
# Chapter 4 Homework
# Your name:
my $string = "There's always more than one way to do it!";
print "Enter a test expression: ";
# Get user keyboard input. The user must type one of the words in the $string variable
# to match the $string pattern.
# chomp the user input
# If $string equals input
# Print Congratulations you guessed part of the pattern
# else
# print Sorry, but no match.
8. Write a Perl script named “1_100.pl” that will add all the numbers from 1 to 100. (15 pts)
9. Write a Perl script named “[Link]” that will print a hash or an array named “flavors”,
flavors will be your favorite flavors. Your script should print: (15 pts)
I like (your flavor choice) milkshakes
I like (your flavor choice) milkshakes
I like (your flavor choice) milkshakes
Bonus Problem!
(5 points added to your homework grade if you answer this correctly. No points deducted for not completing it.)
Use the given file named “[Link]”. Write a gawk script that will transform the contents of [Link] into the following:
(note there is a blank line between each version of the lines) (15 pts)
line 1: I am just a poor boy
line 1 reversed: boy poor a just am I
line 2: Though my story's seldom told
line 2 reversed: told seldom story's my Though
line 3: I have squandered my resistance
line 3 reversed: resistance my squandered have I
line 4: For a pocket full of mumbles such are promises
line 4 reversed: promises are such mumbles of full pocket a For
line 5: All lies and jests
line 5 reversed: jests and lies All
line 6: Still a man hears what he wants to hear
line 6 reversed: hear to wants he what hears man a Still
line 7: And disregards the rest
line 7 reversed: rest the disregards And