Friday, September 03, 2010

O.S. Second Assignment Answers.

Q.1.Invoke vi editor with filename file1.
Ans:
vi file1

Q.2 Insert following lines in file1 and save the content.
a. This is invocation of vi editor.
b. We can invoke in vi editor with file name
c. We are in command mode which is default mode.
d. We can go in insert mode using I,a,A,I,o,O. This is example of insert mode.
e. You can also user r,R,s,S to go in insert mode for replacement of words.
Ans:
I - for insert
then write the above statements.

Q.3 Write a command to go to the 5th line and append “Appended” word at the end of line.
Ans:
i - for insert
then 5+shift+g
e - for reach end of the word
then Append
a. This is invocation of vi editor.
b. We can invoke in vi editor with file1.
c. We are in command mode which is default mode.
d. We can go in insert mode using i,I,a,A,o,O. This is an example of insert mode. Appended.
e. You can also user r,R,s,S to go in insert mode for replacement mode of words.

Q.4 Insert blank line at above of current line
Ans:
shift+o - used for insert a blank line above the current line.

Q.5 Write a command to display ‘*’ 70 times .
Ans:

Q.6 Goto the first line first character and replace it with ‘Z’ without going into insertion mode.
Ans:
1+shift+g - used for reach the first line.

Q.7 Save your work and write command to exit from vi editor with saving and without saving.
Ans:
With saving use - :x
without saving use - :q!

Q.8 Save the current file content in file2 within the vi environment.
Ans:
:w file2 - used for Save the current file content in file2 within the vi environment.
vi file2 - used for show the content in file2.
 
Q.9 Save 5th line of file1 in file3.
Ans:
5+shift+g - used for reach the fifth line.
:.w file3 - used for save the current line work in file3.
vi file3 - used for show the content in file3.

Q.10 Goto line 2, Now save from current line to last line in file4.
Ans:
2+shift+g - used for reach the second line.
:2,$w file4 - used for save from line 2 to last line in file4.

Q.11 Insert some text in current file and without saving restart computer and try to recover that content.
Ans:
:r - for recover

Q.12 Write a command to reach in first line on 5th word.
Ans:
1+shift+g - reach the first line.
w - for begening of the word.

Q.13 Write a command to move at line extremes.
Ans:
shift+g - used for end/extream of the line.

Q.14 Delete 5th line.
Ans:
5+shift+g - reach the fifth line.
dd - used for delete specific the line.

Q.15 Copy 4th line and paste it after 4th line.
Ans:
4+shift+g - reach the fourth line.
yy - used for coppy/yank.
Shift+P - used for paste it after (4th) specific line.

Q.16 Copy first 3 lines and paste it at end of line.
Ans:
1+shift+g - reach at first line.
3yy - coppy first three line.
shift+g - reach end of the line.
Shift+P - used for paste after line.

Q.17 Join last 3 lines.
Ans:
e - reach end of the word.
And then press 2 times for joining the 3 lines.
Shift+j - joining two lines.
Shift+j -

Q.18 Search “vi” in forward direction and see all its next occurrence.
Ans:
:/vi - used for Search “vi” in forward direction.

Q.19 Search “mode” in backward direction and check next occurrence in continue direction.
Ans:
:?mode - Search “mode” in backward direction.

Q.20 Substitute “vi” with “VI” throughout the file for all occurrences.
Ans:
:1,$s/vi/VI/g - Substitute “vi” with “VI” throughout the file for all occurrences.
// Here s - used for substitute. &
// g - for globally.

Q.21 Delete all the lines in current file.
Ans:
ctrl+a - used for select all.
dd - used for delete.

Q.22 Insert any 10 lines of your choice.
Ans:
a - used for insert.
then write any 10 lines of your choice.

Q.23 Copy first 3 lines and paste after 5th line.
Ans:
1+shift+g - reach at first line.
3yy - Copy first 3 lines.
5+shift+g - rerach at fifth line.
shift+p - paste after 5th line.

Q.24 Paste above copied lines using repeating last command.
Ans:
5+shift+g - used for reach at fifth line.
e - used for end of the word.
. - used for repeating last command.(paste after fifth line.)

Q.25 Undo the last operation.
Ans:
(small) u - used for Undo the last operation.

No comments: