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

You can handle input and output in UNIX/Linux in many ways. In this project, you

ID: 3913115 • Letter: Y

Question

You can handle input and output in UNIX/Linux in many ways. In this project, you create a file that feeds commands into the vi editor. (For this and all projects in the chapter, log in using your own account, rather than logging in as root.) To create a file from which the vi editor reads commands: 1. Use the vi editor to create and then save the file testfile containing the following text (ensure that you don’t enter a blank line after the last line): This is line 1. This is line 2. This is line 3. This is line 4. 2. Type cat testfile and press Enter to check your work. 3. Next, using the vi editor, create and save another text file named commands with one line containing the following vi commands: 2GddGp:x. (See Figure 4-7.) 4. Type cat commands and press Enter to verify the contents of the commands file. 5. Type vi testfile < commands and press Enter. (Because the input is from a file and not the keyboard, you might see a warning that the input is not from a terminal. Simply ignore the warning.) This loads testfile into the vi editor and redirects vi’s input to the text in the commands file. The text in the commands file is treated as commands typed on the keyboard. 6. Type cat testfile and press Enter. You see the contents of testfile after the vi commands execute. The contents are: This is line 1. This is line 3. This is line 4. This is line 2.

Im mostly confused on the first part, I type vi textfile to get to the editor type the 4 lines the how do I get that to go back to the command screen and type cat testfile?

Explanation / Answer

If I am not wrong your question is, how to exit from vi editor and get back to the linux shell. If this is correct then following answers the problem, if not let me know in the comments section.

To open a file in vi editor or to create a file : vi FILE_NAME (this will start vi editor)

Now vi editor has two modes: insert(for typing the content) and commannd(to perform actions on the content of the file). By default vi opens into command mode.

To start typing into the file: press 'i' from the keyboard to get into insert mode, here 'i' stands for insert.

After typing all the lines, press 'esc' from the keyboard to go back to command mode.

To save and quit vi editor, use one of the following commands:

<esc>:w : save file

<esc>:wq : save file and quite vi editor (this is what you are looking for)

<esc>:q : quit vi editor without saving file

You can also add '!' after above commands which is forcefull saving or quitting.

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