Using arrays?

I have never used arrays before but I have a script like this:

var1=$(for i in $(cat /tmp/jobs.021013);do $LIST -job $i -all  |
perl -ne 'print  /.*(\bInfo.bptm\(pid=\d{3,5}).*/' | tr -d "(Info=regpid" | tr -d ')'; $LIST -job $i -all  |
cut -f7 -d','| sed -e "s/^\([0-9]*\)\([A-Z0-9.-]*\)\([-0-9-]*\)\(.*\)/\1 \2/";done)
echo $var1
var2=$(for i in $(cat /tmp/jobs.021013);do $LIST -job $i -all  |
perl -ne 'print  /.*(\bInfo.bptm\(pid=\d{5}).*/' | tr -d "(Info=regpid" | tr -d ')'; $LIST -job $i -all  |
cut -f7 -d','| sed -e "s/^\([0-9]*\)\([A-Z0-9.-]*\)\([-0-9-]*\)\(.*\)/\1 \2/";done)
echo $var2

These two variables will store a list such as: Var1= 996 host1 665 host2 334 host3
and Var2 =15516 host1 22223 host2 15151 host3. However, I want a list that looks like this:
996 15516 host1
665 22223 host2
334 15151 host3

Would I need to use arrays to get a list like this? If so, what would be a brief example? Any suggestions would be greatly appreciated.

---------- Post updated at 12:34 PM ---------- Previous update was at 12:25 AM ----------

Did anyone have an idea about creating this list? Do you need more information?

You can store a string like that in the shell. Putting it outside quotes has stripped all newlines and whitespace, however, try echo "$string"

Using it may mean you need to alter the value of IFS.

STRING="a b c
d e f
g h i"

OLDIFS="$IFS"
IFS="
"
for X in $STRING
do
        echo $X
done

IFS="$OLDIFS"

Your code...probably needs to be replaced. It's full of useless uses of cat and does so many external calls to perl, cut, sed, tr, that it's extremely redundant and monstrously inefficient. And so overcomplicated that I can't even tell what you're trying to do, at this point.

1 Like

Corona:

You gave me a whole new perspective on what I was doing and I'm able to make this script much better. Thanks for your expert help!:slight_smile: