# 把 以下資料檔 d1.txt d2.txt 予以整合
d1.txt====================abc:12bob:25cdc:36OK:121Tomy:99Jack:108d2.txt====================Jack:9cdc:8OK:11Tomy:22bob:5abc:88試寫一 script 來處理 d1.txt d2.txt 使其變成abc:12:88bob:25:5cdc:36:8Jack:108:9OK:121:11Tomy:99:22
My script:
#!/bin/bash
for VAR1 in `cat ./d1.txt | sort`
do
for VAR2 in `cat ./d2.txt | sort`
do
if [ `echo $VAR1 | cut -d: -f1` = `echo $VAR2 | cut -d: -f1` ]; then
echo $VAR1\:`echo $VAR2 | cut -d: -f2`
fi
done
done
References: