Both vi editor and cat command are used to input contents in a file.
1. vi Editor :
vi editor stands for the visual editor which is an intelligent editing tool in UNIX Operating System used for reading, creating files, editing them, and more. It is the default editing tool in UNIX.
Command to open a particular file :
It has three modes :
- Command Mode : The vi editor always opens in this mode. It is where all the commands are accepted.
- Insert/Input Mode : The file is opened in the input mode and the contents of the file are written or edited here.
- Execution Mode : The execution mode is invoked by the ‘:’ command from the command mode. Then the commands are read into the command mode.
The way to access each mode from one another has been explained in the image below.
2. cat Command :
The cat command stands for concatenate. It is also used to create new files, read and update already existing files. They are also used for joining multiple files together or copying a file’s content to another one.
Examples of cat Command :
- To create and add some content to a file.
cat > newfile This is a new file that is not empty.
- To read or display the contents of an existing file.
- To merge two files into a new one.
cat file1 file2 >> file3
There are a lot of other commands using cat. However, there are certain limitations to both of their usage.
Difference between vi Editor and cat Command :
|S.NO.||vi editor||cat command|
|1.||vi editor opens an editor tool to work.||It works on the dollar prompt itself.|
|2.||vi editor works in three modes – command, insertion, execution mode.||There is no concept of modes in the cat command.|
|3.||Using a vi editor, the contents of the file can be edited throughout the file.||Using a cat command, the contents of a file cannot be edited. Only more lines could be added or the content of the file can be completely replaced.|
|4.||There are several commands (i, I, o, O, a, A, r, R, s, S) to get to the insertion mode which decides the location of the cursor in the file. This helps in editing the file from wherever the user wants.||There are no commands to decide the location of the cursor inside the file. It always gives the option to edit from the location of last insertion.|
|5.||Copying the contents a file is done manually using the yy command. First the contents of a file are copied and then inserted in the new one.||Copying the contents a file is very handy. It can be done with one simple instruction using the command :|
cat file1 > file2
|6.||Contents of multiple files cannot be copied at a time.||Contents of multiple files can be copied at a time.|
|7.||A file can be merged but only with the one being currently edited.||Merging multiple files is easy and can be done through a single command.|
|8.||In case the system crashes, vi editor let’s one save versions of the file.||There is no scope for saving files that can be edited later.|