please use linux or unix to complete Diff command The diff command displays differences between two files on a...

50.1K

Verified Solution

Question

Programming

please use linux or unix tocomplete

Diff command

The diff command displays differences betweentwo files on a line-by-line basis. It displays the differences asinstructions that you can use to edit one of the files ( using thevi editor) to make it the same as the other. Whenyou use diff, it produces a series of linescontaining Append (a), Delete(d), and Change (c) instructions.Each of these lines is followed by the lines from the file that youneed to append, delete, or change. A less than symbol(<) precedes lines from file1.A greater than symbol (>) precedes lines fromfile2.

You will now need four files. These are telnos, telnos2,telnos3, telnos4. These files are all short files thatcontain names, departments, and telephone numbers. This is whatthey look like.

telnos

telnos2

Hale Elizabeth Bot   744-6892
Harris Thomas Stat 744-7623
Davis Paulette Phys 744-9579
Cross Joseph   MS    744-0320
Holland Tod    A&S   744-8368

Hale Elizabeth Bot   744-6892
Harris Thomas Stat 744-7623
Davis Paulette Phys 744-9579
Holland Tod    A&S   744-8368

telnos3

telnos 4

Hale Elizabeth Bot   744-6892
Harris Thomas Stat 744-7623
Smith John     Comsc 744-4444
Davis Paulette Phys 744-9579
Cross Joseph   MS    744-0320
Holland Tod    A&S   744-8368

Hale Elizabeth Bot   744-6892
Smith John     Comsc 744-4444
Davis Paulette Phys 744-9579
Cross Joseph   MS    744-0320
Holland Tod    A&S   744-8368

To make it easier to copy you can use the * (wildcard) to copythese files. Type in the command:

               cp /tmp/csc3321/telnos* .  

Remember the . (period) means current directory and will copyall of the telnos files at one time and assign them the names thatthey have in the instructor's file

In order to see how diff works, type in:

                difftelnos telnos2

What was the result?
________________________________________________________________________________________________________________________________________________________________________________________________________________________

The difference between these two files (telnos and telnos2) isthat the 4th line in telnos is missing fromtelnos2. The first line that diffdisplays (4d3) indicates that you need to delete the 4th line fromfile telnos to make the two files match. The 4 isthe line number and the (d) is delete. The line number to the leftof each of the a,c, or d instructions always pertains tofile1. Numbers to the right of the instructionsapply to file2. The diff commandassumes that you are going to change file1 tofile2. The next line that diffdisplays starts with a less than (<) symbol indicating that thisline of text is from file1. Next type in:

               diff telnos telnos3

What was theresult?__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

In this case, the second line has the (>) greater than signwhich means that the extra line is in file2. The ameans you must append a line to the file telnosafter line 2 to make it match telnos3. Appendmeans to add on to the end. Next is an example ofthe change feature. Type in the following command:

               diff telnos telnos4

What was the result?__________________________________________________________

What lines do you need to change in order to make the two filesalike?________________________________________________________________________________________________________________________________________________

Notice that the three hyphens indicate the end of the text inthe first file that needs to be changed and the start of the secondfile that needs to be changed. Next, copy telnosto telnos5. What command did you use to do this?________________________________________________________________________


Next, type in:

               diff telnos5 telnos2

What was the answer that you received?_________________________________________________________________________________________________________________________________________________________________________________________________________________

Use the vi editor to change telnos5 to matchthe file telnos2. Then check to see if they arenow alike.

What command did you use?_________________________________________________________

What was the result?__________________________________________________

What is the output of the diff command when the filesmatch?
_______________________________________________________________________________

When the two files are alike, there is no response.Unfortunately, Unix is not always user-friendly.

Uniq Command

The uniq command displays a file, removing allbut one copy of successive repeated lines. If the file has beensorted, uniq ensures that no two lines that itdisplays are the same. Sort telnos andtelnos3 and then send them to a new file calledtel2. Type in the following:

               sort telnos telnos3 > tel2

Next look at the file, tel2. What does itcontain?___________________________________________________________________________________________________________________________________________________________________________________________________

Next issue the command:

               uniq tel2

What was theresult?__________________________________________________________________________________________________________________________________________________________________________________________________________________

The uniq command has three options. Theseare:

-c   Causes uniq to precede each linewith the number of occurrences of the line in the input file

-d   Displays only lines that arerepeated

-u   Displays only lines that are notrepeated

Issue the command:

               uniq -u tel2

What was theresult?__________________________________________________________________________________________________________________________________________________________________________________________________________________

Next, issue the command:

               uniq -d tel2

What was theresult?__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Grep Command

The grep command searches one or more files fora specified pattern. Normally each matching line is copied to thestandard output. Two options that can be used withgrep are:

              -i            ignorecase of alphabetic characters
              -n           precede each line printed by its relative line number in the inputfile

Use the line numbers in the output of grep toanswer the questions in the following sections. Issue thecommand:
              grep -n H telnos

What was printed?________________________________________________________________________________________________________________________________________________________________________________________________________________________

Issue the command:
             grep -ni m telnos

What was printed thistime?___________________________________________________________________________________________________________________________________________________________________________________________________________________

Answer & Explanation Solved by verified expert
3.7 Ratings (648 Votes)
Telnos5 is not availableTelnos5    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students