Showing posts with label Sum of columns. Show all posts
Showing posts with label Sum of columns. Show all posts

Tuesday, May 10, 2011

How to know the character set and collation of mysql database, table and column

Here are the SQL commands to know the character set and collation of mysql database and tables/columns

mysql> use database_name;
mysql> show variables like "character_set_database";
mysql> select data_type,collation_name from information_schema.columns where table_schema='database_name' and table_name='table_name' and column_name='column_name';

Sphere: Related Content

Tuesday, October 7, 2008

Sum of nth column in a file using awk

Today I had to find sum of nth column entries from one of my csv files. I just googled and found a nice way of doing it using awk.
Suppose my input csv file is named as test.out and I have to find sum of all nth column entries of it.

I just created an awk script file named test.awk for setting the FS variable and providing the summation logic to awk.

#test.awk
BEGIN {FS=","}
{ sum+=$COL}
END { print sum }

Then every thing is easy

Use the awk command as follows with input file test.out. Replace 8 with any column index you want.

awk -f test.awk COL=8 < test.out

Sphere: Related Content