Quick bash scripting question

Something I haven’t been able to find the answer to in browsing a number of basic and advanced guides…

To simplify my goal, take the following demonstration:

-I have 2 files:

“letters” which consists of:

a
b
c


“numbers” which consists of:

1
2
3


What is the easiest way to read these variables in such that I can work with them in pairs of “a 1” “b 2” …?

Can variable ‘pairs’ be read in using a "for x in cat letters" type statement? That would work fine for my purposes.

Or, possibly the better solution, what is the easiest way to read the files into 2 separate arrays?

Many Thanks in advance.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quick testing:

declare arrayA=(cat test0.txt)
declare arrayB=(cat test1.txt)
echo ${arrayA[0]} ${arrayB[0]}

There you go… each line is put into an index of the array so if
test0.txt had ‘a’, ‘b’, and ‘c’ on one line each and test1.txt had ‘1’,
‘2’, and ‘3’ on one line then the commands above result in printing out ‘a 1’.

Good luck.

mstrickland16 wrote:
> Something I haven’t been able to find the answer to in browsing a number
> of basic and advanced guides…
>
> To simplify my goal, take the following demonstration:
>
> -I have 2 files:
>
> “letters” which consists of:
>
> a
> b
> c
>
> ----------------------------------
>
> “numbers” which consists of:
>
> 1
> 2
> 3
>
> ----------------------------------
>
> What is the easiest way to read these variables in such that I can
> work with them in pairs of “a 1” “b 2” …?
>
> Can variable ‘pairs’ be read in using a "for x in cat letters" type
> statement? That would work fine for my purposes.
>
> Or, possibly the better solution, what is the easiest way to read the
> files into 2 separate arrays?
>
> Many Thanks in advance.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJK+eh8AAoJEF+XTK08PnB5sVkQANEhfaXDy9a1MS1r4akhL4dE
FH7B0GpvPs5uc68Gvqf2bs2ORIXbymzNJ8sKgXGWCGkE44dcq2PWXPgqr3GFci2A
iCUwHSelI80SoEFEULWuGMQLcXcoMw8Fc3ewMTo6I6s7llXMq6f6fGjxFpIa8mv3
ReQCd1KBsXKKDblwINKqstsVdyRm3eVOGqUeiejQZymp/SQQbmTWXr8Qrklv6eLV
pTC9rdJRCGJzn1O4CRuc5WUFriqPDuuNVImzjxy9t8H7KND25zt3P2hFa6/+HczA
PMTmYEQWg0j9svQba23WjLugeF3YXDk2Eyqw/jUpeOXKz9QNY3Vs8dcxxJCWhrye
UxW4lmi2G6EXK853e+jaGgbQ5qazJiCSVKoYCrG9ehzqH7l/XJhtYC4iKFPKBjEJ
4qTvv+6UKLrBW1UQWGa6HwzQxz7rnYPIqF/s8JWPuOHwz+4Z8xFjd5ZjpYUNR9DU
e+wsr1o6bap9iG6qnSk4DJ/WqqMLAg0O6F/RtLPjsyM4NEaitYfciS0Cgvl5vdXV
vc1/VOjt227/KtUNPuNY6OGZX0P2A2cQHFATSztuICW/+Fv+fiBfSr5pV07A0DRf
OcYEjx2SBN0exQgv8UVhXZvGAnVziRzGTzRMXL7ihRh853/fIT7pY4q+4umedd1g
XoSWJACDq/NGDj4QcPxw
=cwgu
-----END PGP SIGNATURE-----

paste them together and read them using loop


paste file1 file2 | while read a b
do
  echo $a $b
done

paste file1 file2 |awk ‘{print $1,$2}’ (for less typing)