Chapter 4 Assignment
Chapter 4 Assignment
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.
grep –wn the search_me.txt
d. find any string that starts with “ab” and ends with “ed”
egrep –w ab.*ed search_me.txt
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)
Find –iname “*” -atime +30 –type f | cpio -ov > changed_30_zipped.txt
3. Write a sed command that will indent all the lines of a text file named text.txt and redirect the output to a file
named “ind_text.txt” (10 pts)
sed 's/^/ /' text.txt > ind_text.txt
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:
1.displays a message that says “Reminder to me: call Mom!”
2.the message will appear every Sunday, every week, every month at noon
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)
7. Finish the following Perl script and name it pattern.pl: (10 pts)
#!/usr/bin/perl
# Chapter 4 Homework
# Your name: Tyler Harrison
# Get user keyboard input. The user must type one of the words in the $string variable
$var = <STDIN>
# to match the $string pattern.
# chomp the user input
chomp $var
8. Write a Perl script named “1_100.pl” that will add all the numbers from 1 to 100. (15 pts)
$Counter = 1;
$Addded = 0;
9. Write a Perl script named “flavors.pl” that will print a hash or an array named “flavors”,
flavors will be your favorite flavors. Your script should print: (15 pts)
my %flavors=(
"Chocolate" , "White Chocolate",
"Cake", "Cheese Cake",
"Frozen Yogurt", "Vanilla",
);
my @Treats = keys%flavors;
for my $Treats (@Treats){
print "My favorite flavor of '$Treats' is $flavors{$Treats}\n";
}
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 “boxer.txt”. Write a gawk script that will transform the contents of boxer.txt into the following:
(note there is a blank line between each version of the lines) (15 pts)