Pages

grep The UNIX School

Thursday, March 1, 2012

15 different ways to display the contents of a file

  Looking at the file contents is one such activity which a UNIX developer might be doing in sleep also. In this article, we will see the umpteen different ways in which we can display or print the contents of a file.

Let us consider a file named "a", with the following  contents:
a
b
c
1. The first is the most common cat command:
$ cat a
a
b
c

Tuesday, February 28, 2012

Different ways to split the file contents

   In one of our earlier articles, we saw different ways to join all lines in a file. In this article, we will see the different ways in which we can split the file contents of a file.  Some even refer to this as converting rows into columns of a file.

Let us assume a file, say "a" with the following contents:
$ cat a
a,b,c,d

Tuesday, February 21, 2012

Login to a UNIX account from Windows without password

   UNIX users login to their unix boxes umpteen times in a day. Every time, while logging in, we give username and passwords which, takes quite a bit of time, if you happen to login many times in a day. In this article, we will see how we can login to a UNIX account without providing username and password using ssh.

Logging into an UNIX account usually happens in 2 ways:

1. User is already in a UNIX box or server. He tries to login to another UNIX server from the first one.
2. User logs into the UNIX box using putty installed in his Windows system.

Thursday, February 9, 2012

C program to multiply, divide and find reminder for x by 4 without arithmetic operators?

  One of my friends asked me an interesting interview question. The question is like this: How to multiply, divide and find reminder of a number X by 4 without using arithmetic operators?

   Since we are not supposed to use arithmetic operators, none of the +,-,*,/% can be used. Binary operators always help us in this regard.

Tuesday, January 24, 2012

join command


   join command is used to join  two files based on a key field present in both the files. The input files can be separated by white space or any delimiter. join can be looked at like the join functionality in any RDBMS(database). However, the only difference being in the database join we get only the columns which we give in the select clause, in case of unix join, you get all the columns of both the files. And yes, the join can be done using only one key field, not multiple.

1. Let us consider 2 sample files a1 and a2. a1 containing bank account numbers and the balance in the account. a2 containing bank account numbers and the account names.

LinkWithin

Author of the The UNIX School

Author of the The UNIX School
Guru Prasad