Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

**University of Science and Technology** **Faculty of Computer Science and Information Technology** **Open Source Operating Systems** **Lab (3) Date 27-04-2024** **[Text processing commands]** **Description**: The students in this exercise, first create the text files with at least 15 lines an...

**University of Science and Technology** **Faculty of Computer Science and Information Technology** **Open Source Operating Systems** **Lab (3) Date 27-04-2024** **[Text processing commands]** **Description**: The students in this exercise, first create the text files with at least 15 lines and then extract specified text from files, using head, tail, od, wc ,diff, commands with attributes. Using the above mentioned commands students get familiarize with the file system of Linux. **Lab Learning Outcomes:** Introduction Text processing commands **Lab Instructions:** The lab instructor has to follow the steps below to demonstrate to the students the main text processing commands. 1. **Display the first 10 lines of file:** The command to display the first few lines (default is 10) of file is **head command Options/Flags** -------- ------------- **Meaning** **-q** **-v** -------- ------------- 2. **Display the last 10 lines of file** The command to display the last few lines (default is 10) of file is **tail command Options/Flags** -------- ------------- **Meaning** **-q** **-v** -------- ------------- 3. **Display the contents of file in specified format** The command to display the contents of the file in specified format is Consider the following file named city. The contents are To display the contents of this file in octal values, the command is **The result is:** **od command Options/Flags** ---------- ------------- **Flag** **Meaning** **-i** **-f** **-h** **-c** ---------- ------------- 4. **Count the number of lines, words and characters in a file** **Example:** 1- Create a file "student" with contents: 2- execute the command wc \$ wc student When you apply the command, you will get the result like If we count there are 13 characters in the file, but as the output we get 16. WHY? **wc commandOptions/Flags** ---------- ------------- **Flag** **Meaning** **-l** **-w** **-c** ---------- ------------- 5. **compare and display the difference of two files.** **\$ diff *file1* *file2*** 6. **Editing and creating of files in Linux ( using vi)** **vi**  is an interactive text editor which is *display-oriented*: the screen of your [terminal](http://www.computerhope.com/jargon/t/terminal.htm) acts as a window into the file you are editing. Changes you make to the file are reflected in what you see.\ Using **vi** you can insert text anywhere in the file very easily. Most of the **vi** commands move the [cursor](http://www.computerhope.com/jargon/c/cursor.htm) around in the file. You can move the cursor forward and backward in units of characters, words, sentences, and paragraphs. Some of the operators, like **d** for delete and **c** for change, can be combined with the motion commands to make them operate on entire words, paragraphs, etc., in a natural way. vi filename The screen will clear and the text of your file will appear on the screen. If **filename** doesn\'t exist yet, **vi** will start you in a new file, and when you tell it to save your work, it will use the **filename** that you specified. **\* example:** **create a file named address using vi editor** 1. Ooen vi editor: \$ vi address 2. press esc key 3. press i key 4. Enter the file contents echo "Mohammed Ali Mohammed" echo "University of Science and Technology" echo "College of Computer Science" echo "Omdurman" 5. press esc key 6. :wq ( to save and exit) **The file will be created.** 7. **Use the command** **\$ vi address** **To display or edit the file contents.** **Exercises (To be solved in Classroom):** - **Task 1** Using text processing commands such as Head, tail, od, wc, diff, with options. - **Task 2** The students copy the execution output from the terminal and paste it in output file created with vi editor.

Use Quizgecko on...
Browser
Browser