C2110 UNIX and programming Lesson 4 / Module 3 -1C2110 UNIX and programming Petr Kulhanek kulhanek@chemi.muni.cz National Center for Biomolecular Research, Faculty of Science Masaryk University, Kamenice 5, CZ-62500 Brno PS / 2020 Distance form of teaching: Rev1 Lesson 4 / Module 3 C2110 UNIX and programming Lesson 4 / Module 3 -2Text Editors ➢ vi, vim, nano ➢ Graphic Text Editors (gedit, kwrite, kate) C2110 UNIX and programming Lesson 4 / Module 3 -3vi/vim, nano Editor vi / vim is a standard text editor on UNIX-type operating systems. It only works in text mode and its use is non-trivial. • It's a good idea to learn how to open a file, switch to edit mode, edit text, save your changes, and exit the editor. • It enables scripting (use of variables, cycles, fields, associative fields), e.g., for creating automatic texts from read data. • Despite you run the command vi in the classroom, the vim program will start automatically (Vi IMporoved) • There is a difference in control between the original vi and vim. Editor nano is the default text editor in some distributions (UBUNTU). • Less versatile than vim • More straightforward control C2110 UNIX and programming Lesson 4 / Module 3 -4vi – Casics Editor working modes extended command mode command mode insert mode EscEnter a, c, i, o, s, A, C, I, O, R, S: File changes i text will be inserted from cursor position a text will be inserted behind cursor position Start the editor Exit the editor $ vi start editor $ vi filename start editor and open file filename : q ends editor : q! exits the editor without saving changes : w saves file : w filename saves file with name filename :wq exits and saves the file Additional functionality accompanying document! C2110 UNIX and programming Lesson 4 / Module 3 -5- nano More straightforward control - the menu at the bottom suggests possible actions. Use the combinations or individual letters to select an action ^letter – e.g. ^ X is a combination of Ctrl + X M-letter – e.g., M-M is a combination of Alt + M Start the editor $ nano start editor $ nano filename start editor and opening file filename C2110 UNIX and programming Lesson 4 / Module 3 -6Exercise 1 1. On the WOLF cluster, create a text file using editor vi and insert a short text Lorem Ipsum. 2. Save the file as li.txt. 3. Copy the file to your personal computer and view it in a text editor. Solve any complications with ends of lines according to the type of OS on your computer. 4. Edit / change the file on your computer. 5. Copy the modified file to a WOLF cluster under the name li2.txt. 6. On the WOLF cluster, concurrently view the files li.txt and li2.txt in a text editor, each in a separate terminal. C2110 UNIX and programming Lesson 4 / Module 3 -7- kwrite Extended functionality: kate C2110 UNIX and programming Lesson 4 / Module 3 -8- gedit C2110 UNIX and programming Lesson 4 / Module 3 -9Exercise 2 1. On the WOLF cluster in the editor vi, write a text that will contain ten lines. There will be two or more words on each line. Save the text to file mydata.txt. 2. By command wc verify that the file mydata.txt has ten lines. 3. Using pipe(s), write a sequence of commands that print only the number of words in the file on the screen mojedata.txt. 4. In a graphical text editor (of your choice), create a file that will contain ten words, each word on a new line. Save the text to a file second_data.txt. 5. Use the paste command to create the file all_data.txt which will contain the contents of the files mydata.txt and second_data.txt side by side. 6. By command wc verify that the file all_data.txt contains exactly ten lines. 7. Open the file all_data.txt in a graphical text editor and verify its contents visually. 8. Try working in individual text editors and choose the one that works best for you. C2110 UNIX and programming Lesson 4 / Module 3 -10Text Editors in VM C2110 UNIX and programming Lesson 4 / Module 3 -11Text Editors - Installation Try individual text editors in your installation of Ubuntu 18.04 LTS. If they are not available, install them as follows: $ sudo apt-get install vim $ sudo apt-get install kwrite $ sudo apt-get install kate $ sudo apt-get install gedit $ sudo apt-get install nano If asked, enter the password for your account. By default vi editor is installed in a compatible mode, which should be replaced by an extended version (vim). For the installation, see above.