0

:) well i want to read line and save first and second column from file.o And i want to save it into two dimensional array in bash. Filtration is ok its doing the right think. BUT i dont know how to check if the array is empty ( i mean that it saved nothing to that array so its all from the file) . Secondly im getting error on FUNCTION and RELIANCE that command was not found and again echo is not working, tried to google everything but it seems that no one is working with two indexed dimensional arrays. Ty for any tip!

#!/bin/bash
declare -a NAMES
declare -a FUNCTION
declare -a RELIANCE
index=1
index1=1
for a in file.o 
do
  NAMES[$index]=$a  
  until [ nm file.o | grep -o '[UTBGCD].*' | awk '{print $2}' | awk "NR==$index1" -eq 0 ]
  do 
    FUNCTION[$index][$index1]=$( nm file.o | grep -o '[UTBGCD].*' | awk '{print $2}' | awk "NR==$index1" )
    RELIANCE[$index][$index1]=$( nm filea.o | grep -o '[UTBGCD].*' | awk '{print $1}' | awk "NR==$index1" )
    echo ${FUNCTION[$index][$index1]} 
    index1=$((index1+1))  
  done
  index=$((index+1)) 
done
Vrsi
  • 43
  • 1
  • 1
  • 4
  • By the way, all-uppercase names for non-environment, non-builtin variables is contrary to best practices -- opens you up to namespace collisions. – Charles Duffy Mar 22 '14 at 18:12
  • 1
    You would get more answers, if you ask in a form what is easily testable (so, not with `nm *.o |...` and like. So provide: 1) sample input data and 2.) the wanted output.. – clt60 Mar 22 '14 at 18:17
  • You probably want to use a different language for this type of data processing; `bash` isn't designed for it. – chepner Mar 22 '14 at 19:15

1 Answers1

0

Bash does not support multidimensional arrays. However, you can fake it in one of two ways. First, there's associative arrays:

declare -A array
x=1 y=2
array["${x}_$[y}"]=value

Second, with fixed-size arrays, you can simply do some math.

declare -a array
x_max=100
x=1 y=2
array[(y*x_max)+x]=value
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • Hm okey so it seems quite hard to do what i want to do. Maybe you can help me. The point is that i need to read that two columns from file and save 1columns and second columns + save the name of file. And the script should be working with any count of files. – Vrsi Mar 22 '14 at 18:12
  • If you can write a clearer explanation, post it as a separate question. Alternately, you might consider joining Freenode's #bash channel, and we can provide (potentially abrasive) guidance on refining that question until it's actionable. – Charles Duffy Mar 22 '14 at 18:14