You can do this with the following script:
#!/usr/bin/bash state=0 for i in $(paste file1 file2) ; do if [[ $state -eq 0 ]] ; then state=1 save=$i else state=0 echo $save and $i fi done
With two input files:
$ cat file1 1 2 3 4 5
and
$ cat file2 a b c d e
You will get the following result:
1 and a 2 and b 3 and c 4 and d 5 and e
This script uses insertion to basically create a new sequence of arguments alternating between two files, and then a very simple state machine for collecting and processing pairs.
Keep in mind that this will not work if your lines contain a space, but I assume this is not a problem, since your original script was not there either.
source share