![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is it possible to draw table/matrix using shell script? | jakSun8 | Shell Programming and Scripting | 2 | 03-18-2009 10:53 PM |
| help for writing shell script to export table data | sankarg | Shell Programming and Scripting | 3 | 10-18-2006 06:01 AM |
| Alter Table Shell Script | ankitgupta | Shell Programming and Scripting | 2 | 10-06-2006 06:01 AM |
| update a oracle table using shell script | ann_124 | Shell Programming and Scripting | 2 | 12-18-2004 07:24 PM |
| Creating a hash table using shell script | jyotipg | UNIX for Advanced & Expert Users | 2 | 10-29-2003 05:37 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Reading a table in a shell script
Dear all:
I want to write a script capable of reading specific rows and collumns of a table, into a variable. Just imagine i have a file named table.dat which contains: GENERAL INFORMATION Col 1 Col2 Col3 1 1 2 2 3 3 4 4 What i want to do is reading, for each line, the data contents of col1 and col 2 (assigning them to variables, instead of writing them to files), in order to do some processing with those results. Does anyone have a clue on how to accomplish this task? Many thanks in advance Luis Carvalheiro |
|
||||
|
Again...the table
I whish to thank the speed of your comments. I followed those instructions but I think i missed something. To make my intempts clear, i'll copy a general "table" whose contents i wish to read (a kind of cut&paste, basically)
---> table start This is the table title, which doesn't need to be read (9) COLUMN LINE COUNT : 1632 531 52.000 1641 617 52.000 1651 604 52.000 1651 605 52.000 1652 601 52.000 1652 604 52.000 1652 605 51.000 1652 606 52.000 ----> table end Ok. what i want is to read sequentially the numbers in COLUMN and LINE, i.e., 1632, 531; 1641, 617, and so on. For the time being, i don't care about the COUNT value. I'm sorry if this sounds like a lame question... Thankfull: Luis |
|
||||
|
Your text needs to have some known attributes such as a colon after your column headings for this to work:
Code:
{
IGNORE_FL=T
while read COLUMN LINE COUNT
do
# Ignore blank lines
if [[ ${#COUNT} -eq 0 || ${COLUMN} = --* ]]; then
continue
fi
# COUNT variable will have the colon description terminator (":"), set IGNORE_FL to F and skip line
if [[ ${COUNT} = *: ]]; then
IGNORE_FL=F
continue
fi
# Ignore all lines until actual columns are found
if [[ ${IGNORE_FL} = T ]]; then
continue
fi
print "Column = ${COLUMN} / LINE = ${LINE}"
done < file.dat 2> /dev/null
}
|
|
||||
|
Code..with your help
Once again, i thank you all for your patience in helping me. At the time being, the code looks like this
#!/bin/bash #later, i'll copy teste.gif to teste$TIMESTAMP.gif TIMESTAMP=`date "+%d%m%Y%H%M"` #I don't want to change the original file, so let's make a copy cp map.gif mapa.gif while read COLUNA LINHA do echo "COLUNA : $col" echo "LINHA : $lin" convert -fill red -draw 'text $col,$lin "*"' mapa.gif teste.gif done < below As you can see, the basic idea is to plot a kind of a map, with the help of imagemagik's convert. The basic idea is to populate a pre-existing map with *'s, read from the file "below" (Columns 1 and 2). The output from the code is erroneous, since i get the following error message (for each line...): COLUNA : LINHA : convert: Non-conforming drawing primitive definition `text'. Could you have the kindness of commenting the code? Thanks again: Luis |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|