0% found this document useful (0 votes)
161 views

Chapter 4 Assignment

This document provides instructions for a Chapter 4 assignment due on October 10th. It includes 9 questions to be answered using M.S. WORD, Linux commands like grep, sed, and cronjobs, and Perl scripts. The bonus problem involves using gawk to reverse and print the lines of a file called boxer.txt.

Uploaded by

Tyler Harrison
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views

Chapter 4 Assignment

This document provides instructions for a Chapter 4 assignment due on October 10th. It includes 9 questions to be answered using M.S. WORD, Linux commands like grep, sed, and cronjobs, and Perl scripts. The bonus problem involves using gawk to reverse and print the lines of a file called boxer.txt.

Uploaded by

Tyler Harrison
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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.
grep –wn the search_me.txt

b. reverse all lines that don’t contain the word “the”


grep –wv the search_me.txt

c. find every instance of the words “and” and “And”


egrep –w .nd 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

1. Create file here:


cat my_cron.cron
2. Register cronjob here:
crontab my_cron.cron
3. Command to edit cronjob here:
nano my_cron.cron
4. Text to edit cronjob here:
crontab –e
0 12 1-31 1-12 7 echo ‘ Reminder to me: call Mom!’

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)

Tar –cvf tarred_up .

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”
ls *.txt | cpio –ov > cwd_bak

b. list all of the files in in the backed-up “cwd_bak”


*.txt

7. Finish the following Perl script and name it pattern.pl: (10 pts)

#!/usr/bin/perl
# Chapter 4 Homework
# Your name: Tyler Harrison

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
$var = <STDIN>
# to match the $string pattern.
# chomp the user input
chomp $var

# If $string equals input


$var = lc $var
If (var == $string)
# Print Congratulations you guessed part of the pattern
print “Congratulations you guessed part of the pattern”
# else
else
# print Sorry, but no match.
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)

$Counter = 1;

$Addded = 0;

while ($Counter < 100){

$Added = $Added + $Counter ;

$Counter = $Counter + 1;}

print "1-100 added up is '$Added'"

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)

I like (your flavor choice) milkshakes


I like (your flavor choice) milkshakes
I like (your flavor choice) milkshakes

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)

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

You might also like