Concatenate strings line by line

Hi, I have a noob question . Can someone help me how to concatenate line by line using this variables?

var1:
Apple|
Banana|

var2:
Red
Yellow

then how can I concatenate both line by line? in which the result would be:
Apple|Red
Banana|Yellow

just to generate a row result i was using:

var1=$(
cat <<-__EOF__
APPLE
BANANA
__EOF__
)

var2=$(
cat <<-__EOF__
RED
YELLOW
__EOF__
)

I tried using unix paste but I do not know how to use it if it is a variable.

Thanks for your help.

Can you not have the contents of variable in files ?

If then, you can use

paste file1 file2
1 Like

I cant because if another user is using the page. it may cause conflict.

This is the solution I used by the way in case someone might need it also.

 allData=$\(echo "$var1" | awk -v var2="$var2" '
  \{split\(var2,arr1,"\\n"\);print $0""arr1[NR]\}
  '\)

allData holds now the concatenated data line by line.

With bash you can use process substitution:

var1="Apple|
Banana|"

var2="Red
Yellow"

paste -d '' <( echo "$var1" ) <( echo "$var2" )

:

thanks a lot. I think I am going to use the process substitution.

would it be faster compared to the awk solution that I am using?

Use the time command to see which is faster.

Thanks a lot sir. :slight_smile:
using paste is much faster compared to the solution using awk.