(Solved) : Objectives View Create Files Using Cat Command Combine Files Redirection Operator Using Ca Q41375643 . . .

Objectives: View and create files using cat command Combine files with a redirection operator using cat command Combine fileStep 2. Create the file and manual entry the contents with cat command In addition to viewing the content of files, you can ub. Use the command to combine the contents in fruit and fruit2 files side-by-side and direct it to a file called newfruit4 whCommand Format: Vi (option(s)] [filename] a. What command did you change to the practice directory? b. Using this command to1. Then type j. Type word. Type to move the cursor to the last line on the screen. key to go forward one word. Type to go bacd. Which command allows you to save the current file you are editing under another name and remain in vi to continue editingObjectives: View and create files using cat command Combine files with a redirection operator using cat command Combine file with the paste command Become familiar with the Linux/UNIX vi text editor Review the three vi Modes Review keystrokes to move between vi modes Create a new file with vi Review the save and quit commands Create a new file with vim Open an existing file with vim text editor Use manipulation and transformation commands, which include sed, tr, and pr Use the pipe (1) redirection Background: In this lab, you will use two Linux/UNIX text editing tools: the vi (pronounced “vee eye”) and vim editors. These text editors are primarily used for creating and modifying files that customize your work environment and for writing script files to automate tasks. System administrators use text editors to create and modify system files used for networking, security, application sharing, etc. The vi editor became a part of the Linux/UNIX operating system shortly after UNIX’s inception and is universally available with Linux/UNIX systems. The vi editor is a very flexible and powerful editor with many options. These will be reviewed here with examples of their use. vim (vi with some improvements) editor is similar to vi editor, we can use vim editor to edit an existing file. Also, you will use advanced UNIX/Linux commands to find files and specific strings contained in files. By piping, you can take the output from one command and use it as input to another command for further processing. Use the diagram of the sample Class File System directory tree to assist with this lab. Class File Tree Structure home CSC156 your UserName user2 dante + cos Step 2. Create the file and manual entry the contents with cat command In addition to viewing the content of files, you can use the cat command to create and entry the contents of file. In the following example, you can type information into the file and end the session by type Ctrl+d, Creating the file janes_research by using cat > command Example: cat > jane_research a. Enter the command to verify the location, what command do you use? b. What is the result? c. What command do you use to change to the practice directory by using the absolute pathname? d. Use the cat command to create the my_list file under current practice directory. (Hint: using cat command to create the new file.) What do you use at the command prompt? e. Type the following lines of text, exactly as they appear. Press Enter at the end of each line: Football Basketball Skates Soccer ball Golf ball f. Press Ctrl+d to exit this command. Step 3. Combine the files one after the other by using cat command Also, you can use the cat command to combine two files one after the other. For example, $ cat file1 file2 → To combine and display the file and file2 one after the other on the screen. $ cat file1 file2 > newfile → To combine the file 1 and file2 one after the other and save the result onto the newfile. a. Combine one file after the other for the fruit file and fruit2 file under the user2 directory and save the combined file named as newfruit3 onto the current practice directory. What command will you use? b. Check the file type of newfruit3, what command do you use? (Hint use the file command) c. View/display the contents of the newfruit3 file, what command will you use? Step 4. Combine the files side-by-side by using paste command The paste command combines files side by sides, whereas the cat command combines files end to end. For example, paste vegetables bread > food, the vegetables and bread files are combined, line by line, into the file named food. a. What command do you use to change to the user2 directory? b. Use the command to combine the contents in fruit and fruit2 files side-by-side and direct it to a file called newfruit4 which is under the practice directory. What command do you use? c. Also, combine the fruit file and fruit2 file side by side under the user2 directory from your current location and save the combined file named as newfruit5 onto the practice directory, also, it will be separated by the comma”, instead of the tab key, what command will you use? Step 5. Review the Three vi Modes There are three modes of operation in vi. Understanding the function of these three modes is the key to working with vi. All commands available with vi can be classified in one of the three modes. The table below lists the modes and a brief description of each. Review the 3 modes and answer the following questions. Mode Command mode Entry mode Function / Characteristics Initial default mode for creating and editing files, cursor positioning and modification of existing text. All commands are initiated from this mode. Used for entry of new text. Entering an insert command such i insert), a (append) and o (open new line) will take you from command mode to entry mode. Entry commands are stand-alone and are entered without pressing the Enter key. Used for saving your work and quitting vi. Type a colon to get to this mode. Pressing the Enter key or Esc key returns to command mode. Last-line mode a. Which vi mode is primarily used to enter new text? b. Which vi mode is used to save your work and quit vi? c. When you start the vi editor, which mode is the default? Step 6. Review keystrokes to Move Between vi Modes The table below shows how to switch modes and get from one mode to another. Review the keystrokes required to move between modes and answer the following questions. From Mode To Mode Commands / Keystrokes Command Entry Command Last-line Entry Last-line Entry Command Last-line Command Last-line Entry i (input), o (open new line), a (append to existing line) Press Esc (Escape) Colon ) Press Esc or Enter Press Esc to return to Command mode, then enter a colon Press Enter or Esc to return to Command mode, then enter an insert command a. Which single-character alphabetic commands will put vi in Entry mode? b. Which key will return vi to Command mode from either Last-line or Entry mode? c. Which command will put vi into Last-line mode from Command mode? Command Format: Vi (option(s)] [filename] a. What command did you change to the practice directory? b. Using this command to create and open a new file called myvifile. What does the vi document screen look like? c. Press the lower case letter i to begin inserting text at the first line. Is there any indication on the bottom of screen that you are in Insert Entry mode d. Type your own name and press Enter after your name. If you make a mistake do not try to correct it at this time. Were you able to enter text in Insert mode? e. Press the key to leave Insert Entry mode and return to Command mode. What happens to the line at the bottom of the screen? (Hint: use your own words to describe it) f. Press i again to re-enter insert mode. Type the following text, pressing Enter after each line to move to the next line. Be certain that you press Enter after the final line you type to move the cursor to the next line. If you need to delete any characters, press the Backspace key. Files contain text. Text contains lines. Lines contain characters. Characters form words. Words form text. [Press Enter) g. Press key go to Command mode. Type . (period) once. The vi editor inserts the five lines that you typed in Step f. How many lines does the file have now? _(Hint: look at the bottom-right corner) Command jor Down arrow k or Up arrow h or left arrow I or right arrow | Н Cursor Positioning Commands Movement Down one line Up one line Left one character position Right one character position Upper-left corner of the screen Last line on the screen Beginning of the last line The line specified by a number, Back one word (including punctuation) Forward one word End of the current line Beginning of the current line 0 (zero) or h. Press key to make certain you are in command mode. Press the arrow keys to move up, right, left and down one character at a time. Type 1. Then type j. Type word. Type to move the cursor to the last line on the screen. key to go forward one word. Type to go back one to move to the beginning of the second line. Command dw 3dw dd 3dd d$ do Basic Text Deletion Commands Meaning Delete character at the cursor Delete word (or part of word to right of cursor) Delete three words Delete line containing the cursor Delete three lines Delete the characters(texts from the cursor to the end of the line Delete the characters(texts from the cursor to the beginning of the line k. Type dd (but do not press Enter) to delete second line. Press w to go to the next word, “contains”. Then type to delete the current word (so the line now reads “Text lines”), and type i to enter insert mode. I. Type consists of between “Text” and “lines”. Be certain to include the extra “s”and a space after “of”. Press the arrow keys to move the cursor to the extra “s” in “consists”, and then press Esc to switch to command mode. m. To delete the current character (the extra “s”), type (but do not press Enter) Step 8. Save and Quit Commands In the previous steps, you created a file and saved it with the w (write) command and exited vi with the q (quit) command. You also exited vi/vim without saving any changes using the q! command. There are several Save and Quit commands available with vi. The following table lists some of the more common ones. Note: Save and Quit commands (except for ZZ) are entered ONLY when in Last-line mode. Command w w new filename wa ZZ (upper case) Save and Quit Commands Meaning Write buffer (Save changes and continue working in vi) Write buffer to new filename (continue working in vi) Write buffer (save changes) and quit vi Save changes and quit vi. Alternative to wg (command mode) Quit without saving changes Write buffer (save changes) and quit vi (The I will override read only permissions if you are the owner of the file.) wq! a. Most save and quit commands are entered in which mode? b. Which command will allow you to exit vi and not save any of you changes? C. Which two commands listed in the table perform the same function? d. Which command allows you to save the current file you are editing under another name and remain in vi to continue editing the current file? d. Then type a colon (shift + 🙂 to go from Command mode to Last-line mode. Are you now at the bottom left corner of the screen at a colon () prompt? If not, press Esc again, and enter another colon. f. Type a lower case w (write – to save your new file), followed by a lower case q (quit – to exit the vi editor). What was the result of the wq commands? What is your prompt now? 9 The new file should be saved in your practice directory on the hard disk. Display a long listing of this directory to verify that your file is there. What command do you use? How many bytes are in the file? h. What command will you to view the contents of your practice folder? (Notice that there is now a file called myvifile listed). Next type file myvifile command and what type of file is myvifile ? _ i. At the command prompt, type and view the contents of file myvifile on the screen. (Hint: use the cat command to view the content of the file.) Step 9. Create a file with vi or vim editors: If you start vi or vim and specify an excising file name, it is opened for editing Use the commands in the tables to accomplish these tasks: a. Type vi sample 1 (or vim sample1) under practice directory to create a new text file called sample 1. At the command prompt, type My letter and press Enter. Why was nothing displayed to the screen? b. To switch from command mode to insert mode to allow the typing of text, press I. Next type My letter and notice that this text is displayed to the screen. c. Press Esc. Did the cursor move? What mode are you in now? d. Press left arrow two times until the cursor is under the last tin letter. Press the x key What happened? _Next type i to enter insert mode and type the letter “h” Did the letter “h” get inserted before or after the cursor? e. Press _ to switch back to command mode and then move your cursor to the end of the line. Next type the letter “o” (lower case) to open a line underneath the current line and enter _mode. Show transcribed image text Objectives: View and create files using cat command Combine files with a redirection operator using cat command Combine file with the paste command Become familiar with the Linux/UNIX vi text editor Review the three vi Modes Review keystrokes to move between vi modes Create a new file with vi Review the save and quit commands Create a new file with vim Open an existing file with vim text editor Use manipulation and transformation commands, which include sed, tr, and pr Use the pipe (1) redirection Background: In this lab, you will use two Linux/UNIX text editing tools: the vi (pronounced “vee eye”) and vim editors. These text editors are primarily used for creating and modifying files that customize your work environment and for writing script files to automate tasks. System administrators use text editors to create and modify system files used for networking, security, application sharing, etc. The vi editor became a part of the Linux/UNIX operating system shortly after UNIX’s inception and is universally available with Linux/UNIX systems. The vi editor is a very flexible and powerful editor with many options. These will be reviewed here with examples of their use. vim (vi with some improvements) editor is similar to vi editor, we can use vim editor to edit an existing file. Also, you will use advanced UNIX/Linux commands to find files and specific strings contained in files. By piping, you can take the output from one command and use it as input to another command for further processing. Use the diagram of the sample Class File System directory tree to assist with this lab. Class File Tree Structure home CSC156 your UserName user2 dante + cos
Step 2. Create the file and manual entry the contents with cat command In addition to viewing the content of files, you can use the cat command to create and entry the contents of file. In the following example, you can type information into the file and end the session by type Ctrl+d, Creating the file janes_research by using cat > command Example: cat > jane_research a. Enter the command to verify the location, what command do you use? b. What is the result? c. What command do you use to change to the practice directory by using the absolute pathname? d. Use the cat command to create the my_list file under current practice directory. (Hint: using cat command to create the new file.) What do you use at the command prompt? e. Type the following lines of text, exactly as they appear. Press Enter at the end of each line: Football Basketball Skates Soccer ball Golf ball f. Press Ctrl+d to exit this command. Step 3. Combine the files one after the other by using cat command Also, you can use the cat command to combine two files one after the other. For example, $ cat file1 file2 → To combine and display the file and file2 one after the other on the screen. $ cat file1 file2 > newfile → To combine the file 1 and file2 one after the other and save the result onto the newfile. a. Combine one file after the other for the fruit file and fruit2 file under the user2 directory and save the combined file named as newfruit3 onto the current practice directory. What command will you use? b. Check the file type of newfruit3, what command do you use? (Hint use the file command) c. View/display the contents of the newfruit3 file, what command will you use? Step 4. Combine the files side-by-side by using paste command The paste command combines files side by sides, whereas the cat command combines files end to end. For example, paste vegetables bread > food, the vegetables and bread files are combined, line by line, into the file named food. a. What command do you use to change to the user2 directory?
b. Use the command to combine the contents in fruit and fruit2 files side-by-side and direct it to a file called newfruit4 which is under the practice directory. What command do you use? c. Also, combine the fruit file and fruit2 file side by side under the user2 directory from your current location and save the combined file named as newfruit5 onto the practice directory, also, it will be separated by the comma”, instead of the tab key, what command will you use? Step 5. Review the Three vi Modes There are three modes of operation in vi. Understanding the function of these three modes is the key to working with vi. All commands available with vi can be classified in one of the three modes. The table below lists the modes and a brief description of each. Review the 3 modes and answer the following questions. Mode Command mode Entry mode Function / Characteristics Initial default mode for creating and editing files, cursor positioning and modification of existing text. All commands are initiated from this mode. Used for entry of new text. Entering an insert command such i insert), a (append) and o (open new line) will take you from command mode to entry mode. Entry commands are stand-alone and are entered without pressing the Enter key. Used for saving your work and quitting vi. Type a colon to get to this mode. Pressing the Enter key or Esc key returns to command mode. Last-line mode a. Which vi mode is primarily used to enter new text? b. Which vi mode is used to save your work and quit vi? c. When you start the vi editor, which mode is the default? Step 6. Review keystrokes to Move Between vi Modes The table below shows how to switch modes and get from one mode to another. Review the keystrokes required to move between modes and answer the following questions. From Mode To Mode Commands / Keystrokes Command Entry Command Last-line Entry Last-line Entry Command Last-line Command Last-line Entry i (input), o (open new line), a (append to existing line) Press Esc (Escape) Colon ) Press Esc or Enter Press Esc to return to Command mode, then enter a colon Press Enter or Esc to return to Command mode, then enter an insert command a. Which single-character alphabetic commands will put vi in Entry mode? b. Which key will return vi to Command mode from either Last-line or Entry mode? c. Which command will put vi into Last-line mode from Command mode?
Command Format: Vi (option(s)] [filename] a. What command did you change to the practice directory? b. Using this command to create and open a new file called myvifile. What does the vi document screen look like? c. Press the lower case letter i to begin inserting text at the first line. Is there any indication on the bottom of screen that you are in Insert Entry mode d. Type your own name and press Enter after your name. If you make a mistake do not try to correct it at this time. Were you able to enter text in Insert mode? e. Press the key to leave Insert Entry mode and return to Command mode. What happens to the line at the bottom of the screen? (Hint: use your own words to describe it) f. Press i again to re-enter insert mode. Type the following text, pressing Enter after each line to move to the next line. Be certain that you press Enter after the final line you type to move the cursor to the next line. If you need to delete any characters, press the Backspace key. Files contain text. Text contains lines. Lines contain characters. Characters form words. Words form text. [Press Enter) g. Press key go to Command mode. Type . (period) once. The vi editor inserts the five lines that you typed in Step f. How many lines does the file have now? _(Hint: look at the bottom-right corner) Command jor Down arrow k or Up arrow h or left arrow I or right arrow | Н Cursor Positioning Commands Movement Down one line Up one line Left one character position Right one character position Upper-left corner of the screen Last line on the screen Beginning of the last line The line specified by a number, Back one word (including punctuation) Forward one word End of the current line Beginning of the current line 0 (zero) or h. Press key to make certain you are in command mode. Press the arrow keys to move up, right, left and down one character at a time. Type
1. Then type j. Type word. Type to move the cursor to the last line on the screen. key to go forward one word. Type to go back one to move to the beginning of the second line. Command dw 3dw dd 3dd d$ do Basic Text Deletion Commands Meaning Delete character at the cursor Delete word (or part of word to right of cursor) Delete three words Delete line containing the cursor Delete three lines Delete the characters(texts from the cursor to the end of the line Delete the characters(texts from the cursor to the beginning of the line k. Type dd (but do not press Enter) to delete second line. Press w to go to the next word, “contains”. Then type to delete the current word (so the line now reads “Text lines”), and type i to enter insert mode. I. Type consists of between “Text” and “lines”. Be certain to include the extra “s”and a space after “of”. Press the arrow keys to move the cursor to the extra “s” in “consists”, and then press Esc to switch to command mode. m. To delete the current character (the extra “s”), type (but do not press Enter) Step 8. Save and Quit Commands In the previous steps, you created a file and saved it with the w (write) command and exited vi with the q (quit) command. You also exited vi/vim without saving any changes using the q! command. There are several Save and Quit commands available with vi. The following table lists some of the more common ones. Note: Save and Quit commands (except for ZZ) are entered ONLY when in Last-line mode. Command w w new filename wa ZZ (upper case) Save and Quit Commands Meaning Write buffer (Save changes and continue working in vi) Write buffer to new filename (continue working in vi) Write buffer (save changes) and quit vi Save changes and quit vi. Alternative to wg (command mode) Quit without saving changes Write buffer (save changes) and quit vi (The I will override read only permissions if you are the owner of the file.) wq! a. Most save and quit commands are entered in which mode? b. Which command will allow you to exit vi and not save any of you changes? C. Which two commands listed in the table perform the same function?
d. Which command allows you to save the current file you are editing under another name and remain in vi to continue editing the current file? d. Then type a colon (shift + 🙂 to go from Command mode to Last-line mode. Are you now at the bottom left corner of the screen at a colon () prompt? If not, press Esc again, and enter another colon. f. Type a lower case w (write – to save your new file), followed by a lower case q (quit – to exit the vi editor). What was the result of the wq commands? What is your prompt now? 9 The new file should be saved in your practice directory on the hard disk. Display a long listing of this directory to verify that your file is there. What command do you use? How many bytes are in the file? h. What command will you to view the contents of your practice folder? (Notice that there is now a file called myvifile listed). Next type file myvifile command and what type of file is myvifile ? _ i. At the command prompt, type and view the contents of file myvifile on the screen. (Hint: use the cat command to view the content of the file.) Step 9. Create a file with vi or vim editors: If you start vi or vim and specify an excising file name, it is opened for editing Use the commands in the tables to accomplish these tasks: a. Type vi sample 1 (or vim sample1) under practice directory to create a new text file called sample 1. At the command prompt, type My letter and press Enter. Why was nothing displayed to the screen? b. To switch from command mode to insert mode to allow the typing of text, press I. Next type My letter and notice that this text is displayed to the screen. c. Press Esc. Did the cursor move? What mode are you in now? d. Press left arrow two times until the cursor is under the last tin letter. Press the x key What happened? _Next type i to enter insert mode and type the letter “h” Did the letter “h” get inserted before or after the cursor? e. Press _ to switch back to command mode and then move your cursor to the end of the line. Next type the letter “o” (lower case) to open a line underneath the current line and enter _mode.

Expert Answer


Answer to Objectives: View and create files using cat command Combine files with a redirection operator using cat command Combine …