Answered step by step
Verified Expert Solution
Link Copied!

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:

M07.03- 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 1 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
M7-Organizing 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 1
Read the handout on accessing the Virtual Lab in Canvas to access your virtual machine. Log in to the sysadmin
account with the password netlab123 and open the terminal program.
Task 2
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 3
Create two text files named file1 and file2.
file1 file
001
056
127
258
INFO 1111: Linux I
INFO-1111: LINUX I 2
file2 file
002
056
167
369
Capture a screenshot showing you successfully completed this task.
Add your screenshot for this task on the answer sheet as Screenshot 1.
Task 4
The comm command compares 2 similar sorted files. Use the following command:
comm file1 file1
This command will output 3 columns. The first column (left) displays text lines uniq to file1. The second column
(middle) displays lines unique to file2 and the 3rd column (right) displays the lines common to both files.
Task 5
To suppress or hide one of the columns of the output for comm use the -1,-2 or -3 option. For example, to
suppress the third column execute the following command:
comm -3 file1 file2
INFO 1111: Linux I
INFO-1111: LINUX I 3
Task 6
Use the comm command to compare file1 and file2 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 2.
Task 7
Make a copy of the avengers.txt file created in a previous assignment. Name the copy avengers2.txt.
Task 8
Open the new avengers2.txt file in vim and delete 2 lines from the file so it differs from the original
avengers.txt. Save and close the file
Task 9
Use the comm command to compare the avengers.txt and avenger2.txt 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 1.
Task 10
To override the error received by unsorted files, use the --nocheck-order option with comm.
comm --nocheck-order avengers.txt avengers2.txt
Capture a screenshot showing you successfully completed this task.
Add your screenshot for this task on the answer sheet as Screenshot 3.
INFO 1111: Linux I
INFO-1111: LINUX I 4
Task 11
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 --output-delimiter option. For example, to separate columns using the
plus sign use the following command.
comm --nocheck-order --output-delimiter=+ avengers.txt avengers2.txt
Task 12
Compare the 2 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 4.
Task 13
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 avengers2.txt, we can see what we need to change with
the following command:
diff avengers.txt avengers2.txt
You many have different results with your output than the image above based upon how you changed your
avengers2.txt file.
Reading the output of the diff command can be challenging. The can help interpret the output.
9d8- The 9 represents the 9th line, the d represents delete and 8 represents what would appear in the file
being compared. So if the 9th line (spider-man) was deleted from the avengers.txt file then it would be the
INFO 1111: Linux I
INFO-1111: LINUX I 5
same as line 8 in the avengers2.txt file.
< spider-man - The < represents the file listed first (avengers.txt is left of avengers2.txt in the diff command).
spider-man is the line that is different.
11d9- The 11 represents the 11th line. The d represents delete and 9 represents what would appear in the 9th

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Print out the type of the variable with a c + + function

Answered: 1 week ago

Question

What magazine and ads did you choose to examine?

Answered: 1 week ago