Sunday, July 7, 2013

Ubuntu: How to sort file contents using command ?


In this article, I will share my understanding of sort command with some examples. One important point to notice is that the file contents must be on separate line. If file contains only single line then we are not able to observe the effect of sort command. Before jumping directly to examples, here are some of its variations

To sort file contents                             : sort filename.txt
To sort according to column contents   : sort –k (column number) filename
To sort in reverse order                       : sort –r filename
To remove duplicates while sorting      : sort –u filename
  •  Sorting numeric contents
           Suppose file contains only numeric data then file contents are sorted in ascending order of integer values as shown below.
$ cat file
015
004
016
009
003
018
002
020

$ sort file
002
003
004
009
016
018
020
  •   Sorting alphabetic contents
            Suppose file contains only alphabetic data then file contents are sorted alphabetically as shown below.
$ cat file
Ashish Gaigole
Siyaram Vishwakarma
Deepak Jaiswal
Dashrath Sharma

$ sort file
Ashish Gaigole
Dashrath Sharma
Deepak Jaiswal
Siyaram Vishwakarma
  •  Sorting alpha-numeric contents
           In case file has both numeric and alphabetic data then first all numeric data is sorted in ascending order followed by alphabetic data.
$ cat file
Ashish Gaigole
Siyaram Vishwakarma
Deepak Jaiswal
Dashrath Sharma
015
016
004
009

$ sort file
004
009
015
016
Ashish Gaigole
Dashrath Sharma
Deepak Jaiswal
Siyaram Vishwakarma
  •  Sorting file contents according to particular column values
$ cat file
Ashish Gaigole 016 F-42
Siyaram Vishwakarma 015 F-43
Deepak Jaiswal 009 F-44
Dashrath Sharma 004 F-41

$ sort –k 3 file  : file is sorted according to third column in file.
Dashrath Sharma 004 F-44
Deepak Jaiswal 009 F-41
Siyaram Vishwakarma 015 F-43
Ashish Gaigole 016 F-42

$ sort –k 4 file  : file is sorted according to fourth column in file.
Deepak Jaiswal 009 F-41
Ashish Gaigole 016 F-42
Siyaram Vishwakarma 015 F-43
Dashrath Sharma 004 F-44                         

Saturday, May 18, 2013

Ubuntu: ”How to recover root password ?”


Situation may arise that you want to login as root user and you don’t  know or you forgot the root password. In this case we need to boot in recovery mode. In some cases recovery mode option will not prompt automatically so need to press left shift key while booting. This will prompt option to boot in recovery mode. Once you boot in recovery mode, various options will be available. 

Selecting root option will login you as root in terminal without any password. Now you can create new root user, you can change the password of existing root user. 






After you have successfully changed the password, you need to reboot the system and now you can login with your new password.






For this just refer following commands.

You can get the list of current user                                 cat  /etc/passwd              
                                                  
You can add new user to the system                              useradd username  

 You can set the password of the user                             passwd username


Sunday, May 12, 2013

A HAPPY LIFE or DESERTED ONE….!!


Green house gases absorb the infrared radiations, traps the heat for longer time and makes the atmosphere warmer. It is definitely true that one of the reasons that we are living on earth is because of these green house gases but if we are not careful about their atmospheric levels then they will kill us. According to the latest survey, the amount of greenhouse gases in the atmosphere is highest in last 2 million years. Carbon Dioxide (CO2) is most harmful among all other green house gases.Before the industrial revolution, the problem was not that much serious. Now a days industrialization has become the benchmark for country’s development, almost every industry results in increasing the amount of green house gas in the atmosphere. The problem is much more serious as carbon levels are increasing exponentially. Previously it takes 7000 years to increase CO2 level by some amount but now the carbon dioxide has gone up by the same amount in just 55 years.

                                                     What steps we can take as an individual to minimize the effect? As trees absorb CO2 while photosynthesis we should plant more trees. We can use alternative eco-friendly fuels. We should save electricity, save water, walk whenever possible. If such things are added up by billions of people then definitely it will improve our climatic condition. Everything is in our hand and it’s up to us that what we want? We need to think about our next generation, what type of life you want to give to your generation?  
A HAPPY LIFE or DESERTED ONE….!!

Thursday, May 9, 2013

Ubuntu: How to solve “Could not get lock on /var/lib/dpkg/lock“ problem ?



This one of the most frequent problems that arises while updating the installation packages. In order to solve this problem we need to remove the lock file from dpkg directory.as well as cache directory. After removing the lock we can update the packages without any error.

Remove Lock from dpkg    :     sudo rm /var/lib/dpkg/lock
Remove Lock from cache   :     sudo rm /var/cache/apt/archives/lock
Update packages                :     sudo apt-get update
Upgrade packages              :     sudo apt-get upgrade

Tuesday, May 7, 2013

Ubuntu:Waiting for jockey-backend to exit


After installation of Ubuntu the most common problem is updating or downloading softwares. When we try to update any package or tried to install any software, Ubuntu gives message Waiting for jockey-backend to exit in Update manager. Jockey is tool for installation of third party hardware drivers and need to be disabled safely.

In order to resolve this problem we need to kill this jockey-backend process. Here is solution to do that.

1.Get Administrative access             sudo -i
 
2.Get process id of jockey-backend process    ps -e | grep jockey

3.Kill this process                            kill -9  process_id

Saturday, May 4, 2013

Lets Save Precious Water


Water is one of the most precious natural resource that the human beings got. The important thing is how serious we are about its usage?

The amount of water available on the earth is sufficient for human beings if we use it carefully. As population of the earth is increasing exponentially so is the demand of drinking water but we are wasting large amount of water just because currently we are having its sufficient supply. Currently we have to pay for 20 to 30 rupee for one water bottle. The most of the rural areas are still does not have sufficient water supply. They are supplied by water tankers that so not daily. The condition will become much more worsen in the future if we don’t save water. So let’s join our hands to save water as much as possible.
SAVE WATER, SAVE LIFE....!