Answered step by step
Verified Expert Solution
Question
1 Approved Answer
M 0 7 . 0 3 - ANSWER SHEET - COMPARING AND MANIPULATING TEXT ASSIGNMENT OBJECTIVES: On completing this lab, you should be able to:
M ANSWER SHEET COMPARING AND MANIPULATING TEXT
ASSIGNMENT OBJECTIVES:
On completing this lab, you should be able to:
Compare text from various files using comm and diff.
Manipulate text using paste, join and cut..
PART COMPARING FILES
INSTRUCTIONS:
The Linux command line is incredibly powerful and efficient at processing text in files. This lab will introduce you to
several command line tools used to compare and manipulate text in files. You will also be required to complete tasks
previously covered in prior sections and in class. This lab will use some of the directories and files used in the
MOrganizing Text lab. Perform the task being requested on your vSphere virtual machine. Provide the requested
answer or screenshot as indicated in the task.
TASK
Task
Read the handout on accessing the Virtual Lab in Canvas to access your virtual machine. Log in to the sysadmin
account with the password netlab and open the terminal program.
Task
Change your working directory to the TextFiles directory which was created in a previous lab. If you do not
have this directory please refer to the previous lab.
Task
Create two text files named file and file
file file
INFO : Linux I
INFO: LINUX I
file file
Capture a screenshot showing you successfully completed this task.
Add your screenshot for this task on the answer sheet as Screenshot
Task
The comm command compares similar sorted files. Use the following command:
comm file file
This command will output columns. The first column left displays text lines uniq to file The second column
middle displays lines unique to file and the rd column right displays the lines common to both files.
Task
To suppress or hide one of the columns of the output for comm use the or option. For example, to
suppress the third column execute the following command:
comm file file
INFO : Linux I
INFO: LINUX I
Task
Use the comm command to compare file and file and suppress the first column of the output.
Capture a screenshot showing you successfully completed this task.
Add your screenshot for this task on the answer sheet as Screenshot
Task
Make a copy of the avengers.txt file created in a previous assignment. Name the copy avengerstxt
Task
Open the new avengerstxt file in vim and delete lines from the file so it differs from the original
avengers.txt Save and close the file
Task
Use the comm command to compare the avengers.txt and avengertxt file. The comm command requires files
to be sorted. Since the avengers text files are not sorted you will receive an error. What error do you receive.
Submit your answer for this task on the answer sheet as Answer
Task
To override the error received by unsorted files, use the nocheckorder option with comm.
comm nocheckorder avengers.txt avengerstxt
Capture a screenshot showing you successfully completed this task.
Add your screenshot for this task on the answer sheet as Screenshot
INFO : Linux I
INFO: LINUX I
Task
By default, the comm command separates delimits the output columns with a tab. To change the delimiter
from a tab to another character, use the outputdelimiter option. For example, to separate columns using the
plus sign use the following command.
comm nocheckorder outputdelimiter avengers.txt avengerstxt
Task
Compare the avengers files separating each column with commas
Capture a screenshot showing you successfully completed this task.
Add your screenshot for this task on the answer sheet as Screenshot
Task
Like the comm program, diff is used to detect the differences between files. diff has a lot more features than
comm. It is often used by programmers to examine changes between different versions of code. diff also has
the ability to create diff files or patches that are used by programs to convert one version of a file to another.
If we want compare avengers.txt to be the same as avengerstxt we can see what we need to change with
the following command:
diff avengers.txt avengerstxt
You many have different results with your output than the image above based upon how you changed your
avengerstxt file.
Reading the output of the diff command can be challenging. The can help interpret the output.
d The represents the th line, the d represents delete and represents what would appear in the file
being compared. So if the th line spiderman was deleted from the avengers.txt file then it would be the
INFO : Linux I
INFO: LINUX I
same as line in the avengerstxt file.
spiderman The represents the file listed first avengerstxt is left of avengerstxt in the diff command
spiderman is the line that is different.
d The represents the th line. The d represents delete and represents what would appear in the th
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started