[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to combine two lists without join?



On Mon, Dec 22, 2003 at 01:29:55PM +0100, Gaudenz Steinlin wrote:
> 
> To integrate discover2 into hw-detect I need to combine to lists into
> one without join (which is not available in busybox and not on d-i
> images):
> 
> MODEL_INFOS=$(discover -t all)
> MODULES=$(discover --data-path=linux/module/name all)
> 
> MODEL_INFOS and MODULES now contain a list of vendor/model strings and
> kernel modules (newline separated). I now want to combine these two
> lists to one list with lines of the following form:
> 
> module:model_info
> 
> How can this be done with only the tools available on d-i images? Eric
> Gillespie of Progeny simply keeps repeating that it should be easy and
> I'm almost convinced that I might be stupid, but me and pere didn't find
> an easy way to achieve this. The only thing I can imaging is writing a
> little C program that does this. 

Hello, i have coded this solution, it works with bash (called in posix
mode as sh) but i don't know if it's work with busybox shell. I don't
know i f busybox as harrays and evalutate math expressions with $(( ))
For the math evalutation you can use also

let i = i + 1

instead of

i=$((i = 1))

Don't remove the IFS assignements, is foundamental if your lists are
newline separated. Here the code

#!/bin/sh

function testa() {
    echo "a b"
    echo "b c"
    echo "c d"
    echo "d e"
}

function testb() {
    echo 1
    echo 2
    echo 3
    echo 4
}

function myjoin() {
    i=0
    for str in $1
    do
      ARRAY[$i]="$str"
      i=$((i + 1))
    done
    
    i=0
    for str in $2
    do
      echo "$str:${ARRAY[$i]}"
      i=$((i + 1))
    done
}

A="$(testa)"
B="$(testb)"

IFS="
"

C="$(myjoin "$A" "$B")"

echo "$C" | while read i 
do
  echo "$i"
done



Ciao
-- 
Daniele



Reply to: