Reading a table in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a table in a shell script
# 8  
Old 08-10-2006
to start with......
Code:
while read COLUNA LINHA
do
    echo "COLUNA : $COLUNA "
    echo "LINHA : $LINHA"
    convert -fill red -draw "text $COLUNA ,$LINHA '*'" mapa.gif teste.gif
done < below

# 9  
Old 08-10-2006
Try this:
Code:
{
while read COLUMN LINE COUNT
do
    if [[ ${COLUMN} != +([0-9]) || ${LINE} != +([0-9]) ]]; then
       continue
    fi

    echo "COLUNA : ${COLUMN}"
    echo "LINHA : ${LINE}"
    convert -fill red -draw 'text ${COLUMN},${LINE} "*"' mapa.gif teste.gif 

done < file.dat 2> /dev/null
}

# 10  
Old 08-10-2006
Quote:
Originally Posted by vgersh99
to start with......
Code:
while read COLUNA LINHA
do
    echo "COLUNA : $COLUNA "
    echo "LINHA : $LINHA"
    convert -fill red -draw "text $COLUNA ,$LINHA '*'" mapa.gif teste.gif
done < below

Whoops, I didn't really try to validate the convert command so you better look at vgersh99's example as well. The double quotes are necessary.
# 11  
Old 08-10-2006
tmarikle,
you need double-quotes in order to have the shell expand the 'read-in' vars - COLUNA and LINHA.

I don't know much of the 'convert' myself......
# 12  
Old 08-10-2006
convert

Dear all:

the variable passing to convert is a little tricky, and i could solve the problem in convert with

convert -fill red -draw "text $LINHA,$COLUNA *" mapa.gif mapa.gif

As you've probably noticed, the code was wrong at the stage of invoking convert: i need to accumulate my data points...so the file always remains the same (mapa.gif).

The actual problem now resides on reading only the the pairs COLUNA, LINHA, on my table...since the script reads all the columns in the same line, as depicted on this simple output:

COLUNA : 1632
LINHA : 531 41.132 -8.397 52.000
convert: Non-conforming drawing primitive definition `text'.

For the time being, the code is:

#!/bin/bash

TIMESTAMP=`date "+%d%m%Y%H%M"`

cp map.gif mapa.gif


while read COLUNA LINHA
do
echo "COLUNA : $COLUNA"
echo "LINHA : $LINHA"
convert -fill red -draw "text $LINHA,$COLUNA *" mapa.gif mapa.gif
done < below

And the contents of file "below" is:
TOTAL DE PIXELS COM VALORES ABAIXO DO LIMIAR (9) : 261


COLUNA LINHA LATITUDE LONGITUDE COUNT :

1632 531 41.132 -8.397 52.000
1641 617 37.643 -7.611 52.000
1651 604 38.146 -7.311 52.000
1651 605 38.107 -7.307 52.000


Thank you all for your precious help and comments.
# 13  
Old 08-10-2006
Quote:
Originally Posted by vgersh99
tmarikle,
you need double-quotes in order to have the shell expand the 'read-in' vars - COLUNA and LINHA.

I don't know much of the 'convert' myself......
That's what I was attempting to say but maybe it wasn't clear. I only noticed the single quotes after your previous post. I was just partially being too lazy to edit the post and partially trying to prompt the OP to read your correction on that particular line.
# 14  
Old 08-10-2006
Quote:
Originally Posted by luiscarvalheiro
COLUNA : 1632
LINHA : 531 41.132 -8.397 52.000
convert: Non-conforming drawing primitive definition `text'.

...
while read COLUNA LINHA
do
echo "COLUNA : $COLUNA"
echo "LINHA : $LINHA"
convert -fill red -draw "text $LINHA,$COLUNA *" mapa.gif mapa.gif
done < below

And the contents of file "below" is:
TOTAL DE PIXELS COM VALORES ABAIXO DO LIMIAR (9) : 261


COLUNA LINHA LATITUDE LONGITUDE COUNT :

1632 531 41.132 -8.397 52.000
1641 617 37.643 -7.611 52.000
1651 604 38.146 -7.311 52.000
1651 605 38.107 -7.307 52.000


Thank you all for your precious help and comments.
That is because read needs to know how many things to read. If you specify while read COLUMN LINE JUNK then columns 3 through the end of the line will be dumped into read variable JUNK.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Help with pivoting table shell script

input file txt file 2000 1 name 2000 2 addr 2000 3 phone 2000 4 email 1000 1 name 1000 2 addr 1000 3 phone 1000 4 email 3000 1 name 3000 2 addr 3000 ... (4 Replies)
Discussion started by: senmatrix
4 Replies

2. Shell Programming and Scripting

Shell Script Table

Hi, i need a bit help. I must write a script with shell- and sed-commands, which reads a table from stdin and writes a html-table on stdout (so i can open it with a web browser). The number of columns must be a parameter for the script, so i can start it for example with: "./htmltab.sh 3... (3 Replies)
Discussion started by: scruffytramp
3 Replies

3. Shell Programming and Scripting

Reading a table from shell

i want to do something like this from shell, for any user without having to enter any passwords i want to store the value in the option_value column into a variable select option_value from `$databasename`.`wp_options` where option_name="template"; what is the command i should use? ... (0 Replies)
Discussion started by: vanessafan99
0 Replies

4. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

5. Shell Programming and Scripting

Shell script to query Oracle table

Hi, unix gurnis I need help for following requirement for writing a shell scritp. log in to oracle database, query one table total records (select count(*) from table1), pass the return value to a file. Thanks in advance (2 Replies)
Discussion started by: ken002
2 Replies

6. Shell Programming and Scripting

Create DB table through shell script

Hi, Can anyone tell me that, How to create table in Oracle database through shell script(ksh). Table contains 3 fields, 1] Emp ID, String, primary key 2] Name, String 3] B Date, date. Thanks in advance. (6 Replies)
Discussion started by: Poonamol
6 Replies

7. Shell Programming and Scripting

Truncating table from a shell script

I am trying to truncate a table using below script. When I ran the script it runs fine but table was not truncated and the spool is empty. I am not sure what is wrong with pl/sql block. #!/bin/ksh # ---------------------------------------------------------------------- # # Created by: XXXX... (2 Replies)
Discussion started by: gunaah
2 Replies

8. Shell Programming and Scripting

Script not reading Data from oracle table properly

Hi, I have a case where i am connecting to the oracle DB and reading a column value.... Script is in production...it was running fine,,,but suddenly now some times its started giving pain.... Script runs dailly....but sometimes its reading data from Oracle DB and sometimes its not rading the... (2 Replies)
Discussion started by: Sagarddd
2 Replies

9. Shell Programming and Scripting

How to connect DB2 table using shell script

Hi All, I want to connect two tables in DB2 using shell script and then compare the contents of two tables field by field. Could any one please help me in connecting database tables using Unix and retriving data from the same. Thanks, Durwas (0 Replies)
Discussion started by: dtidke
0 Replies

10. Shell Programming and Scripting

Alter Table Shell Script

I want to add some columns to a existing tables through a shell script. Please help. (2 Replies)
Discussion started by: ankitgupta
2 Replies
Login or Register to Ask a Question