Question

In: Computer Science

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

please use linux or unix to complete

Diff command

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

You will now need four files. These are telnos, telnos2, telnos3, telnos4. These files are all short files that contain names, departments, and telephone numbers. This is what they 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 copy these files. Type in the command:

                cp /tmp/csc3321/telnos* .  

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

In order to see how diff works, type in:

                diff telnos telnos2

What was the result?
________________________________________________________________________________________________________________________________________________________________________________________________________________________

The difference between these two files (telnos and telnos2) is that the 4th line in telnos is missing from telnos2. The first line that diff displays (4d3) indicates that you need to delete the 4th line from file telnos to make the two files match. The 4 is the line number and the (d) is delete. The line number to the left of each of the a,c, or d instructions always pertains to file1. Numbers to the right of the instructions apply to file2. The diff command assumes that you are going to change file1 to file2. The next line that diff displays starts with a less than (<) symbol indicating that this line of text is from file1. Next type in:

                diff telnos telnos3

What was the result?__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

In this case, the second line has the (>) greater than sign which means that the extra line is in file2. The a means you must append a line to the file telnos after line 2 to make it match telnos3. Append means to add on to the end. Next is an example of the 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 files alike? ________________________________________________________________________________________________________________________________________________

Notice that the three hyphens indicate the end of the text in the first file that needs to be changed and the start of the second file that needs to be changed. Next, copy telnos to 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 match the file telnos2. Then check to see if they are now alike.

What command did you use? _________________________________________________________

What was the result? __________________________________________________

What is the output of the diff command when the files match?
_______________________________________________________________________________

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 all but one copy of successive repeated lines. If the file has been sorted, uniq ensures that no two lines that it displays are the same. Sort telnos and telnos3 and then send them to a new file called tel2. Type in the following:

                sort telnos telnos3 > tel2

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

Next issue the command:

                uniq tel2

What was the result?__________________________________________________________________________________________________________________________________________________________________________________________________________________

The uniq command has three options. These are:

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

-d   Displays only lines that are repeated

-u   Displays only lines that are not repeated

Issue the command:

                uniq -u tel2

What was the result?__________________________________________________________________________________________________________________________________________________________________________________________________________________

Next, issue the command:

                uniq -d tel2

What was the result?__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Grep Command

The grep command searches one or more files for a specified pattern. Normally each matching line is copied to the standard output. Two options that can be used with grep are:

                -i             ignore case of alphabetic characters
                -n             precede each line printed by its relative line number in the input file

Use the line numbers in the output of grep to answer the questions in the following sections. Issue the command:
               grep -n H telnos

What was printed? ________________________________________________________________________________________________________________________________________________________________________________________________________________________

Issue the command:
              grep -ni m telnos

What was printed this time?___________________________________________________________________________________________________________________________________________________________________________________________________________________

Solutions

Expert Solution

Telnos5 is not available

Telnos5 created using cp command

-d finds duplicate entries

-n, --line-number with H character in file telneos

-i, --ignore-case for ignore-case M or m inside file telnos file

Thanks


Related Solutions

please use linux or unix to complete, and include pictures of the output. Modify the code...
please use linux or unix to complete, and include pictures of the output. Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will sum up numbers from 801 - 1000 Make main thread wait for other threads to finish execution and sum up all the results. Display the total to the...
unix/Linux Create a tar command using the man command and the link referred to in To...
unix/Linux Create a tar command using the man command and the link referred to in To Practice and Explore: Text File Utilities #9. Preliminaries Use the man pages to learn more about tar Review the links referred to in To Practice and Explore: Text File Utilities #9 to see examples of using tar command Perform Use tar "to stuff" three files and then "unstuff" them into a new directory. Include the -v option. Task ll to show the original 3...
How LUNCH meterpreter in Kali Linux. Complete command please. Thank you
How LUNCH meterpreter in Kali Linux. Complete command please. Thank you
Differences Between Linux and Windows Operating Systems Two key differences between a Linux operating system and...
Differences Between Linux and Windows Operating Systems Two key differences between a Linux operating system and a Windows operating system are the concepts of “mounting” and “drive” letters. Provide an example for each. Why is it important to plan disk partitioning before installing Linux? Discuss the advantages of disk partitioning. Also discuss what logical volume management (LVM) is and why or why you might use it.
Provide a full detailed comparison table of the differences between Windows, Solaris, Unix,Linux OS and MacOS
Provide a full detailed comparison table of the differences between Windows, Solaris, Unix,Linux OS and MacOS
unix question please write a program and then show how to use top command that shows...
unix question please write a program and then show how to use top command that shows the zombie process, give snapshot of top command that shows the zombie process Write a very simple program that will show the possibility of having zombie processes. Write a program named zombie.c The main process will create a child. The child prints something like: “I am the child with pid ….. and my parent has ppid ….” Next, the child will sleep for 1...
Unix / Linux 21. Given the following command pipeline, provide a diagram (ascii art) or detailed...
Unix / Linux 21. Given the following command pipeline, provide a diagram (ascii art) or detailed description indicating all the Input/Output (I/O) connections. Every stdin, stdout, and stderr for each command will need to connect to something. grep a < words | wc -l > a_count.txt 22. Explain what is wrong (if anything) with the following command pipeline. cd | ls 23. Stream Editor: Write a sed command to delete digits, but only on lines that end with a period....
Unix / Linux 6. vi editor: In vi command mode, what are the keystrokes you would...
Unix / Linux 6. vi editor: In vi command mode, what are the keystrokes you would type to... Quit the vi editor and save any changes? 7. C language source files, by convention, have the suffix ".c". The associated "header" files have the suffix ".h". What is the command to perform the following task: List all the C source and C header files in the current directory. [Hidden files may remain hidden.] 8. C language source files, by convention, have...
PLEASE USE LINUX/UNIX 1.Use either pico, vi, or cat to create the following file and name...
PLEASE USE LINUX/UNIX 1.Use either pico, vi, or cat to create the following file and name it as “mysedfile”: Name Class1 Class2 Class3 Tom 92 94 88 Nancy 91 85 95 Lisa 99 77 96 Jerry 84 98 90 2. Please use sed command(s) to complete the following tasks. display Tom’s record. display Lisa’s record. display both Tom’s and Lisa’s records. remove the blank line(s) from “mysedfile.” replace all the digits with *.
Using sed unix / linux command how would I execute this: Move the first 2 characters...
Using sed unix / linux command how would I execute this: Move the first 2 characters on each line to the end of the line
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT