Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8)Assume you are editing the main.h file. Write a vim command to append the cont

ID: 3733277 • Letter: 8

Question

8)Assume you are editing the main.h file. Write a vim command to append the contents of main.cpp to the end of the main.h file. Do not assume you know the contents of the main.cpp file.

CS 140 Linux
9)Assume you are editing the main.h file. Write a vim command to change the case of every character, i.e. all lower-case characters become upper-case characters, and all upper-case characters become lower-case characters.

10)Assume you are running vim with no file. Write a sequence of vim commands that will merge the main.h and main.cpp files into a single file, and then write the merged file to "main.cpp" in your home directory

Explanation / Answer

8. In the following question we are appending main.cpp to the end of main.h fle. Let us first understand how to append two files. Let there be two files a.txt and b.txt and merge them to c.txt . The vim command for this would be

% cat [ab].txt >| c.txt
% vim c.txt

Now in the previous case we simply replace the a.txt with main.cpp and b.txt with main.h .Simce the contents are appended in main.h we also replace the c.txt with main.h.Hence the final command should be like this

% cat main.cpp main.h >| main.h
% vim main.h

9. Now as we are already editing the main.h file there is no more need to select the main.h file. Else start the operation with

vim main.h

Now to convert all the uppercase to wercase and vice versa in there we simply need to do the following command

Here it converts all the lowercase characters to uppercase and in case its already a lowercase it converts them to uppercase.This is a single step simultaenious process.

Theres also another process (a little shorter one) with gnu sed

basically in both the cases you need to use the sed commands.

10.Now this case is quite similar to the first case however in this we are not using any file.Let us assume the paths of the two files are ~/main.h and ~/main.cpp thus this can too be done with the cat command.The command will be like this

cat ~/main.h ~/main.cpp > ~/main.cpp

Now this command has one assumption and is the path of the files. Now the first two file names after cat indicated the two files that needs to be merged. and the > sign indicates where they needs to be mergerd and placed,The filename after the > notation gives the actual source. So after execution of this command,they gets merged and combines to the main.cpp file in home directory. (In case the directory is ~/Home and not ~/ simply replace all '~/' with '~/Home/'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote