Skip to main content

Posts

Showing posts from August, 2018

Introduction to awk

awk is  a popular text processing utility in Unix operating system. It is useful in analyzing the text files, especially those which are organized into rows and columns. By the way, awk stands for the names of its inventors Alfred V. A ho, Peter J. W einberger, and Brian W. K ernighan who wrote it in 1977 at Bell Laboratories. Using awk Let us use a file empl.txt for the first few examples, which has names of employees, their (dummy) ids and departments $cat empl.txt Suresh 1 ADM Ramesh 2 TECH Sita 3 TECH Maran 4 ADM Shreya 5 SAL Partha 6 SAL Vandana 7 ADM Nandini 8 ADM Sudama 9 SAL First let us use awk to print only employees from ADM department. $ awk '/ADM/' empl.txt Suresh 1 ADM Maran 4 ADM Vandana 7 ADM Nandini 8 ADM Here  the parameters for awk command must be written in single quotes. This should be followed by input file on which awk command must be applied. Output of the command is displayed on screen. The command '/string/' filters only those

VI editor

I consulted my team regarding the inclusion of vi editor in this blog. (this sounds cooler than I wasted 2 days dillydallying about this topic). I will just give enough introduction to the most popular text editor in Linux editor, enough for you to create/open a file, make changes and save the file.  To start vi editor, you give vi and filename. Modes  The editor has two modes insert mode and command mode. Insert mode is for you to type the content and command mode is for manipulation. i - key starts insert mode esc - key exits the insert mode You can use even the following keys for starting insert mode a - append at the end of word o - start a new line below the cursor O - start a new line above the cursor. While typing remember the fact that, cursor keys are not allowed in insert mode. Quitting the editor First come out of the insert mode by typing esc key and use any of the following combinations - which appear at the bottom of screen :w - save the f

Some more file commands

touch command We have seen how to copy, rename or delete a file. But how would we create a file? Using a text editor? touch command lets you create an empty file. touch file1.txt creates an empty file as can be seen from the above screen shot. But touch command with an existing file will change the access date of a file without opening the file or modifying it in any way.  It just touches the file. more or less? We have seen earlier that cat command will display the contents of a file (similar to type command in Windows) But what happens if the file is large?  cat in that case just displays the entire file and shows back the command prompt without us having time to view the complete file. In these situations, we can use more or less command to display the file, one screen at a time.  more command will display one screen and pause and by pressing Enter key it will scroll by one line.   less command does the same thing. But less allows us to us