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

Linux/Ubuntu sing the vi/vim editor, specify how to execute the following action

ID: 3605087 • Letter: L

Question

Linux/Ubuntu

sing the vi/vim editor, specify how to execute the following actions: 1.- Create a document named doc01.txt with 10 lines each containing the sentence "Yesterday was the day." Write the sentence only one time. 2.- Save the file doc01.txt and exit vi. 3.- Create a document named doc02.txt with 10 lines each containing the sentence "Today is the day to be free with GNU Linux." Write the sentence only one time. 4.- Add the file doc01.txt at the beginning of file doc02.txt. 5.- Save the doc02.txt as doc03.txt 6.- In the document doc03.txt replace the word "Yesterday" by "Today" and the word "was" by the word "is" 7.- Save the file doc03.txt and exit vi. Submit the sequence of Linux statements associated to each section in order to execute the task described above. Write vour solution in a plain text file,

Explanation / Answer

The following are the list of "vi" commands that correspond to your questions. Vi is a flexible editor and there are multifarious steps to achieve the same result. I have provided the steps that are easy to understand and straightforward.

The lines that begin with "#" is for only your understanding.


## 1. Create a document named doc01.txt with 10 lines each containing "Yesterday was the day". Write the sentence only one time
vi doc01.txt
Press i
Type "Yesterday was the day."
Press escape key
Press yy
Type 9p

## Vi editor works with concept of modes. By default (or when you press escape key), the editor is in command mode.
## In this mode, all the vi commands can be executed. When you press, the letter "i", the editor moves into insert mode, wherein the user can insert text into the file
## After you are done with entering the text, Ensure you are in command mode (i.e press escape key) and then type the different vi commands
## "yy" - command will copy the contents of the current line to the default buffer
## "9q" - command will paste the contents of the default buffer - 9 times


## 2. Save the file doc01.txt and exit the vi
:w
:q

## Ensure you are in command mode (i.e press escape key) and then type the different vi commands
## ":w" - command is used to the save the contents of the file from memory to disk
## ":q" - command will quit the Vi editor application


## 3. Create a document named doc02.txt with 10 lines each containing "Today is the day to be free with GNU Linux". Write the sentence only one time
vi doc02.txt
Press i
Type "Today is the day to be free with GNU Linux"
Press escape key
Press yy
Type 9p

## Refer to the comments under section 1 and section 2

## 4. Add the file doc01.txt at the begining of file doc02.txt
:0:read doc01.txt

## To copy the contents of a different file into the current file, you need to use the vi - "read" command
## Ensure you are in command mode (i.e press escape key) and then type the vi commands
## The syntax of the command is ":<insert position>:read <file to be copied>"


## 5. Save the doc02.txt as doc03.txt
:w doc03.txt

## Ensure you are in command mode (i.e press escape key) and then type the vi command
## To save a file with a different name, the syntax of the command is
## ":w <new file name"


## 6. In the document doc03.txt, replace "Yesterday" by "Today" and "was" with "is"
:%s/Yesterday/Today/
:%s/was/is/


## Ensure you are in command mode (i.e press escape key) and then type the vi command
## To search and replace, the syntax of the command is
## ":%s/search-text/replace-text/"
## The %s command will search and replace the text throughout the entire file


## 7. Save the file doc03.txt and exit vi
:wq

## Ensure you are in command mode (i.e press escape key) and then type the vi command
## ":wq" - command will save the contents of the file and then terminate the Vi editor

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