Monday, September 26, 2011

5 different ways to add all the numbers in a file

In this article, we will see the different ways in which can add or sum up all the contents in a file.

Let us take a sample file with the following contents:
$ cat file

Friday, September 23, 2011

5 useful settings to have in .vimrc for a developer

  In this article, we are going to see some of the most important settings which is mandatory for a developer to have in his .vimrc or .exrc file.

set incsearch : When we want to search for something in vi, we put a slash(/) and start typing the word in the escape mode.  On finishing typing, and when we press enter, we get to know whether  the word is present in the file or not.  The setting ‘incsearch’ is a special feature in which you will know whether what you are typing is there or not in the file as you type it. As you keep tying, the matching contents keep getting highlighted. It is like in google search, we get to see the search results as we keep tying.

Wednesday, September 21, 2011

sed - Selective printing

    In this sed article, we are going to see the different options sed provides to selectively print contents in a file.  Let us take a sample file with the following contents:
$ cat file
Gmail 10
Yahoo 20
Redif 18

Tuesday, September 13, 2011

awk - Passing arguments or shell variables to awk

  In one of our earlier articles, we saw how to read a file in awk. At times, we might have some requirements wherein we need to pass some arguments to the awk program or to access a shell variable or an environment variable inside awk. Let us see in this article how to pass and access arguments in awk:

Let us take a sample file with contents, and a variable "x":
$ cat file1
$ echo $x
Now, say we want to add every value with the shell variable x.