Archive for June, 2010

Sort according to the nth Column in Shell Script

You have a file that has multiple columns separated by a specific delimiter and you need to sort it according to a specific column which need not be the 1st column. If its not the 1st column then ordinary sort wont work. So we need to use the parameters of sort to specify the exact column so that it will sort according to that column only. There are parameters in sort like -t and -k, we use this for the sorting. So -t is to specify the delimiter and -k to specify the column needed. For example : We need to get the 3rd column of a csv file(csv file has , as delimiter) the option should be -t, -k3. We can use two more options for the same. -n for sorting the values as numbers instead of considering as text and -r for sorting in descending order ie biggest value on the top. So the final command is :

Continue reading “Sort according to the nth Column in Shell Script” »

, , , , ,

1 Comment

Check the port in which the Mysql is running on

Mysql can be configured to run other ports other than the default port (of 3306). So what will you do when you need to find the port on which a mysql server runs on. If you don’t have access to the server files and can access the server only using the mysql client, the only way to know this is by checking the Global Variable set. We can see all variables by issuing the command:

Continue reading “Check the port in which the Mysql is running on” »

, , , , , , , ,