The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-10-2006
luiscarvalheiro luiscarvalheiro is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 6
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
  #2 (permalink)  
Old 08-10-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
One basic shell construct for doing this is:

Code:
while read COL_1 COL_2 COL_3
do
    <some code using your read variables COL_1, COL_2, COL_3>
done < table.dat
  #3 (permalink)  
Old 08-10-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
You can do something like this:
Code:
while read col1 col2
do
    echo "Col1 : $col1"
    echo "Col2 : $col2"
done < table.dat
Jean-Pierre.
  #4 (permalink)  
Old 08-10-2006
luiscarvalheiro luiscarvalheiro is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 6
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
  #5 (permalink)  
Old 08-10-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
and what exactly in the posted solutions did not work?
  #6 (permalink)  
Old 08-10-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
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
}
Also, be more specific when you indicate that something doesn't work. Provide examples and what you have tried in order to correct the issue. We're not really here to do your work but just to guide you along the way.
  #7 (permalink)  
Old 08-10-2006
luiscarvalheiro luiscarvalheiro is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 6
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0