Problem: Using the vi/vim editor, specify how to execute the following actions:
ID: 3733870 • Letter: P
Question
Problem: Using the vi/vim editor, specify how to execute the following actions: 1.- Create a document named doc0l.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.Explanation / Answer
The commands to be ran on terminal are highlighted in Bold, rest are comments for 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
## 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
:wq
## ":wq" - write to file and quit
## 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
## 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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.