Extract top 20 records from sybase db in shell script

Hi, I am new to advanced scripting.

I need to get top 20 records from database (Sybase) with a condition that all Char/varchar columns should have more than 4 characters.

I need to do this via shell scripting, I have got half logic (on how to get varchar/char columns and stored it in a file). But missing piece, is that how to pass those column names and check for the above said condition.

Please help, its really a urgent .

Do you have any sample pattern you can post, to look at the data.
For example if you are trying to extract top 20 records from (Char/varchar columns) say 5th field, that are more than 4 character long, you can use:
$ awk 'length($5)>4' file |head -n 20

Cheers,

Thanks veri for your response.

the scenario goes like this,

I am getting all table list and from that using sp_help <tablename> getting the column list which has char/varchar.

Those details has been pushed to a file. The file contains say around 10 tables. In each table, consider it has atleast 6 columns (char/varchar)

Now, my query should look like below

select Top 20 * from tablename where len(column1)>4 or len(column2)>4 or len(column3)>4 or len(column5) or len(column6)

column should get appended as per number of columns in the file