Read two files at the same time, and merge their peers into one line to write to a merged file
Shell script:
#!/bin/bash
#set
-x CD ' dirname ' $ '/. /
inas_script_root= ' pwd '
function Make_if_no_existis_dir ()
{local
dir=$1
if [!-e ' ${dir} ' ]
Then
mkdir -P "${dir}"
fi return
0
}
function Union2 ()
{local
File_ Name1=$1 local
file_name2=$2 local
union_dir=${inas_script_root}/file/union
make_if_no_existis_ Dir ${union_dir}
>${union_dir}/union.txt
exec 3< "${inas_script_root}/file/${file_name1}"
EXEC 4< "${inas_script_root}/file/${file_name2}" while
read line1<&3 && read line2<&4
do
echo $line 1 $line 2 >> ${union_dir}/union.txt
done
}
Union2 $
A.txt content:
AAA
BBB
CCC
ddd
Eee
FFF
B.txt content:
AAA
BBB
CCC
DDD
EEE
FFF
GGG
Run the script
SH union_file.sh a.txt b.txt
Get the merged file Union.txt
AAA Triple-A BBB, CCC
CCC
ddd ddd
eee Eee
FFF FFF
GGG GGG
Reference Link: https://www.cnblogs.com/tangxin-blog/p/6531812.html