Simple filters – Marathi


Hello and welcome to the Spoken Tutorial on Simple Filters with Linux. Here we will be learning about head, Tail, sort, cut and paste. All these are command line text manipulation tools. If you see a hash (#) symbol on the Terminal you need to become root to execute those commands sudo su or su root, if you see a dollar symbol on the Terminal you can be an ordinary user to execute those commands. I assume that you did a default installation and did not modify any path where the files are getting saved. I am using Linux for this tutorial. Prerequisites for this module are the ability to use the mouse , keyboard, maximize and minimize buttons on a window. We use the Head command followed by an ascii file name, to display the first 10 lines of a file by default. Let us create a file. Go to Applications>Accessories>Text Editor. I already have these numbers in another file for the sake of time constrain . Let me copy and paste. Hit on File , Save. Name the file as numbers dot txt and hit on save Close this file. Now go to Applications>Accessories>Terminal. Let us try to see if we can see the file we created. Type ls and hit on enter. What we did here is to list all the folders and files on our home directory. Now we can use the cat command to read the contents of the file we created. Cat n-u-m Hit on tab to autofill the file name. Hit on Enter. Let us do the same with head command. head numbers dot txt, enter Now the first 10 lines are displayed. If we want to see the first 5 lines, use the option hyphen n5 in between the head command and the file. Hit on Up arrow, hyphen n5 and Enter. Now the first 5 lines alone are displayed. Let us switch back to the presentation The tail command works exactly opposite to the head command, it displays the last 10 lines of a file by default. I am hitting on ALT and Tab to switch to the terminal. tail numbers dot txt If we want to see just the last 5 lines, use the option hyphen n5 in between the tail command and the file name. hyphen n5, Enter Switch to slides A log file contains events which took place in a system. Auth dot log file maintains log’s for who logged in & who logged out. The most useful option of the tail command is to use hyphen f option to follow the tail of a log file. If a new line is appended to the log file, the tail command will take that as the last line and display 10 lines by default above it. Go to the terminal tail hyphen f forward slash var slash log slash auth dot log Let me resize this terminal Let us open another Terminal , Application->Accessories ->Terminal. Let me resize this terminal so that I can show you in a single screen how tail follows the last line in a log file. Try to su as yourself, hit on enter. Give in some wrong password hit on enter. You will see that the terminal on which tail is running is appended with a new log. The date & time specifies when the authentication failure took place. Type date hit on enter to verify the system date and time. Type Exit to close this terminal. Hit CTRL C to close the running tail command & maximize the screen. We have seen only auth dot log file in the previous example. These are the commonly used log files in Linux. A linux system administrator will look into these log files for more information to troubleshoot his machine if there is a problem. Sort command as the name suggest will sort a file for us in both ascending and descending order. sort numbers dot txt .This would sort our numbers dot txt file in ascending order. Notice something is strange in there, sort just looks at the first character to sort, so 10,11&12 appears before the number 2. To avoid this add the option of hyphen n, hyphen n and Enter Now sort looks at the entire number to sort them. To sort number dot txt in reverse order add an option of hyphen r. We have numbers that repeat in this file, to pull out just the unique numbers add another option of hyphen u . Go to Terminal. Up Arrow U, enter, Previously two 2’s were displayed . Now only one 2 is displayed. Now we will see how we can sort a file based on certain column. Let us create a file and key in these as shown below. Go to Applications>Accessories>Text Editor. I already have the data in another file for the sake of time constrain let me copy & Paste the value, CTRL+C; CTRL+V. File, Save it as marks dot txt, Hit on Save. Don’t mind the special characters on this file I don’t want someone to sue me for giving them low marks Close this file. Let us sort based on the second column of marks dot txt file. Go to the terminal. sort space marks dot txt space hyphen t space open inverted commas space close inverted commas space here hyphen t stands for the delimiter & the space in between the quotes represents it. hyphen k2 for the second column on which sort should be performed. Hit on Enter. Cat marks dot txt This is the original file, if you see Avir is moved above and Bala came below when we sorted based on the second column alone. Cut command is used to cut just certain information from a file. Let us pull out the names from marks dot txt Let us go to the terminal ALT Tab cut space marks dot txt space hyphen d space open inverted commas space close inverted commas space. here in cut command d is the delimiter & the space in between the quotes represents the delimiter. hyphen f2 for the second column. Hit on enter. Paste command will merge corresponding subsequent lines of the files. Let us use both the numbers dot txt and marks dot txt file now. Go to the terminal. Paste numbers dot txt marks dot txt, enter Now the first line of marks dot txt was appended to the first line of numbers dot txt. We can use the redirect key to redirect this output to some other file called concatefile dot txt. Go to the terminal. Hit on Up arrow. Hit on the redirect key which is the Greater than symbol concatfile dot txt. Hit on Enter. Cat concatfile dot txt Let us go to the slide. If we want paste to print out the numbers serially delimited with tab we can use the hyphen s option. Paste hyphen s numbers dot txt Go to the slide. Spoken Tutorial project is a part of Talk to a Teacher project, Supported by the National Mission on Education through ICT,MHRD, Government of India. For more information you can refer to the following link. This is Bala. Thanks a lot for watching this video and dont forget to leave a comment.