Linux Chapter 6 homework questions

Open the vi editor and do the following

(1) Insert the 2019 calendar and name the file 2019.txt.

Answer:
Open the editor with vi, enter a new file for editing, go to the bottom line command, enter the command
: r !cal 2019
to insert the 2019 calendar, and then execute the bottom line command
insert image description here

:w 2019.txt

That is, save the file and name it 2019.txt.

(2) Move the April, May, and June calendars to the right by one tab stop.

Answer:
In the command mode, move the cursor to the beginning of the line for April, May, and June, and execute the command
7>>
to move the calendar of April, May, and June to the right by one tab stop.

(3) Change the title of the calendar from "2019" to "2019 Full Year Calendar".

Answer:
Move the cursor to the title of the calendar, and change the title of the calendar from "2019" to "2019 Annual Calendar" in the input mode.

(4) Delete the calendars for January, February, and March, and restore them.

Answer:
Move the cursor to the beginning of the calendar line for January, February, and March, and execute the command
d11G
, where 8 is the line number of the bottom line of the calendar for January, February, and March.

Press u again to restore.

(5) Move the July, August, and September calendars to the end of the calendar as a whole.

Answer:
This operation is to cut the calendars of July, August and September as a whole, then go to the bottom row of the calendar, and then paste them. The operation is as follows: first move the cursor to the rows of the calendars of July, August and
September First, the calendar of July, August, and September occupies 6 lines as a whole. Execute the cut command
"a7dd
to cut the 6 lines of the calendar of July, August, and September into the buffer area of ​​a;

Move the cursor to the bottom line of the calendar and execute the paste command
"ap

(6) Retrieve the string "30" sequentially, if the last day of each month is "30", delete the string "30".

Answer:
This operation is a search command, and then judge whether the last day of each month is "30", and then delete the string "30", the operation is as follows: Execute the
string search command:
/30
First retrieve the first " 30", and then judge whether the last day of the month is "30", if so, execute the command
d2l
to delete the string "30", then press the n key to retrieve the next "30" string, and so on.

(7) Displays the line number.

Answer:
Execute the bottom line command
: set number

(8) Count the size of the file in the vi editor.

Answer:
Calculate the size of the file in the vi editor, first save the file, for example, save the file and name it 2019.txt, then you can execute the shell command in vi
: !wc 2019.txt

Guess you like

Origin blog.csdn.net/m0_67522355/article/details/125302629