66.6k views
4 votes
Using the vi editor: Create a document with four lines each containing the word "today." Copy the first four lines using only one command. Save the file and exit vi. Reopen the document and change "today" to "yesterday" only on the first four lines.

User HassenPy
by
7.5k points

1 Answer

4 votes

Final answer:

To perform the actions using the vi editor, follow the step-by-step guide which involves entering content, copying lines with a command, saving and exiting, then reopening the file to make specific line changes, and saving once more.

Step-by-step explanation:

The subject of your question is associating with using the vi editor to manipulate text within a file. Here is the step-by-step guide to perform the actions described in your question:

Open the vi editor and create a new file by typing vi filename (replace filename with the actual file name you wish to use).

Enter insert mode by pressing i.

Type the word "today" and press Enter to move to the next line. Do this four times to create four lines.

Now, to copy the first four lines with a single command, first press ESC to exit insert mode.

Type :1,4t4 and press Enter. This command copies lines 1 through 4 and pastes them after line 4.

To save the file and exit, press :wq and then Enter.

To reopen the document, type vi filename in the command line.

Press ESC to ensure you are not in insert mode.

Type 1,4s/today/yesterday/g to change "today" to "yesterday" only on the first four lines.

Finally, save changes and exit by typing :wq and pressing Enter again.

User Dmullings
by
7.3k points