I have 2 files: /tmp/first.txt and /tmp/last.txt
cat /tmp/first.txt
john
adam
max
cat /tmp/last.txt
smith
moore
caviar
I want to combine the contents of these two files, something (output) like this:
john smith
adam moore
max caviar
what i've already did:
first=()
getfirst() {
i=0
while read line # Read a line
do
array[i]=$line # Put it into the array
i=$(($i + 1))
done < $1
}
getfirst "/tmp/first.txt"
for a in "${array[@]}"
do
echo "$a"
done
last=()
getlast() {
i=0
while read line # Read a line
do
array[i]=$line # Put it into the array
i=$(($i + 1))
done < $1
}
getlast "/tmp/first.txt"
for b in "${array[@]}"
do
echo "$b"
done
I've done some look alike (using iteration):
for x in {1..2}
do
echo $a[$x] $b[$x];
done
but the output is only:
max caviar
firstandlastarrays, but never use them. Then you access arraysaandb, but these weren't declared as arrays, they're just the iteration variables in the twoforloops.