Sponsored Content
Full Discussion: Read in Table as a matrix
Top Forums Shell Programming and Scripting Read in Table as a matrix Post 302662989 by servuskelb on Wednesday 27th of June 2012 03:26:45 PM
Old 06-27-2012
Read in Table as a matrix

Dear forum users,
i'm trying to read a table with 40x122 data in a array. Following this, i'd plot each rows again the header of the file in gnuplot.

i was thinking for something like that
Code:
#!/bin/bash 
# reads from the $ips file and assigns to $MYARRAY
#IFS =";" split the line after the ;
#set -- $array save the each row of the line in $1 $2 $3 $4 ....

myfile="Comprasion.txt"
ln=`wc -l $myfile|awk '{print $1}'`
i=1
#echo "$ln"
declare -a sgs
for ((i==1; i<=$ln; i++)); do 
         line=`awk "NR==$i" $myfile`
         #echo "$line"
         declare -a row
         linarray=(`echo ${line// / }`);
         #echo "${#linarray[*]}" # OK.
         #echo "${#linarray[*]}" # OK.
         row=(`echo ${#linarray[*]}`);
         echo "*********"
         #echo "$row"
         r=1
         for ((r==1;r<=$row;r++)); do 
            #echo "variable $i $r"; # OK.
            sgs[${i},${r}]=(`echo ${linearray[$r]}`);
            var=${sgs[${i},${r}]};
         echo "$var";
         done
         #echo "$i";
done

if i run the script, unfortunately, i get nothing. Where do i have problem?

thanks in advance for your help

---------- Post updated at 07:26 PM ---------- Previous update was at 03:43 PM ----------

nobody has a suggestion Smilie

Last edited by servuskelb; 06-27-2012 at 04:03 PM.. Reason: code improved
 

8 More Discussions You Might Find Interesting

1. Solaris

Need some lib in c/c++ to read db table at one go

Hi All, I need some sort of library or module which read the db table at one go and keep in process memory.My problem is that I have a call processing module which handles the network call and goes for db lookup for subscriber profile in oracle db for every call.I am using Oracle Standard Edition... (0 Replies)
Discussion started by: unisuraj
0 Replies

2. Shell Programming and Scripting

Is it possible to draw table/matrix using shell script?

Hi all, I need to create a matrix of variable rows and columns. Right now i have 3 rows and two columns and following values. Output something like TypeA TypeB TestCase1 Pass Fail TestCase2 Pass ... (2 Replies)
Discussion started by: jakSun8
2 Replies

3. UNIX for Dummies Questions & Answers

Teradate table read?

i have to read some data from a teradata table and use them in my shell script.. how do i do that.. we can use BTEQ .. but i don know how to pass the field values as variables to the shell.. please help me.... (8 Replies)
Discussion started by: depakjan
8 Replies

4. HP-UX

how to read routing table

Hi all, Could someone please explain to me how I should read this routing table, # netstat -rn Routing tables Destination Gateway Flags Refs Interface Pmtu 127.0.0.1 127.0.0.1 UH 0 lo0 32808 10.222.47.82 10.222.47.82 UH... (3 Replies)
Discussion started by: rachael
3 Replies

5. Shell Programming and Scripting

Table to Matrix

Hi, I have a table in the format: 1 0 -1 1 0 2 0 1 -1 0 0 0 3 0 1 1 0 0 0 0 0 0 etc. I am trying to input this to a program, however it is complaining about the fact that it is not in matrix format. How do I add 0's to end of the rows to make them even? Thanks in advance! (2 Replies)
Discussion started by: Rhavin
2 Replies

6. Shell Programming and Scripting

How to sort matrix table in UNIX?

Hello All, i have a file sort.txt with below entries. 1 12 10 16 6 4 20 8 15 i need to sort these entries and the out put should come in a single line. 1 4 6 8 10 12 15 16 20 Can you please help me sort this out? (2 Replies)
Discussion started by: sureshk_85
2 Replies

7. Shell Programming and Scripting

awk to convert table-by-row to matrix table

Hello, I need some help to reformat this table-by-row to matrix? infile: site1 A:o,p,q,r,s,t site1 C:y,u site1 T:v,w site1 -:x,z site2 A:p,r,t,v,w,z site2 C:u,y site2 G:q,s site2 -:o,x site3 A:o,q,s,t,u,z site3 C:y site3 T:v,w,x site3 -:p,routfile: SITE o p q r s t v u w x y... (7 Replies)
Discussion started by: yifangt
7 Replies

8. UNIX for Beginners Questions & Answers

Read Table in file and split

HELLO I need your help please , i need to read a file that contain a table like : Name | Status ------------------ DB 1 | UP DB 2 | UP DB 3 | DOWN DB 4 | UP DB 5 | UP the objective to read each line and check if DB is UP or Down and give me the name of Down database.... (10 Replies)
Discussion started by: Abdellah
10 Replies
PG_FETCH_ROW(3) 														   PG_FETCH_ROW(3)

pg_fetch_row - Get a row as an enumerated array

SYNOPSIS
array pg_fetch_row (resource $result, [int $row]) DESCRIPTION
pg_fetch_row(3) fetches one row of data from the result associated with the specified $result resource. Note This function sets NULL fields to the PHP NULL value. PARAMETERS
o $result - PostgreSQL query result resource, returned by pg_query(3), pg_query_params(3) or pg_execute(3) (among others). o $row - Row number in result to fetch. Rows are numbered from 0 upwards. If omitted or NULL, the next row is fetched. RETURN VALUES
An array, indexed from 0 upwards, with each value represented as a string. Database NULL values are returned as NULL. FALSE is returned if $row exceeds the number of rows in the set, there are no more rows, or on any other error. EXAMPLES
Example #1 pg_fetch_row(3) example <?php $conn = pg_pconnect("dbname=publisher"); if (!$conn) { echo "An error occurred. "; exit; } $result = pg_query($conn, "SELECT author, email FROM authors"); if (!$result) { echo "An error occurred. "; exit; } while ($row = pg_fetch_row($result)) { echo "Author: $row[0] E-mail: $row[1]"; echo "<br /> "; } ?> SEE ALSO
pg_query(3), pg_fetch_array(3), pg_fetch_object(3), pg_fetch_result(3). PHP Documentation Group PG_FETCH_ROW(3)
All times are GMT -4. The time now is 01:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy