以下のように2つのファイルがあります
ファイル1
Emp1 Dec10 12Am
Emp2 Dec10 2Am
Emp3 Dec10 4Am
Emp2 Dec10 6Am
Emp1 Dec10 8Am
ファイル2
Emp1 Dec11 12Pm
Emp2 Dec11 2Am
Emp1 Dec11 3Am
Emp3 Dec11 4Am
Emp1 Dec11 5Am
そのため、出力を次のように作成しようとしました。
Emp1 presence on Dec10 was 2 times and on Dec11 was 3 times.
Emp2 presence on Dec10 was 2 times and on Dec11 was 1 time.
Emp3 presence on Dec10 was 1 time and on Dec11 was 1 time.
答え1
この試み、
EMP=(`awk '!seen[$1]++ {print $1}' File1 File2`)
for emp in "${EMP[@]}"
do
DAYS=`awk -v b=$emp '$1==b {print $2}' File1 File2 | sort | uniq -c | awk '{print $2" was "$1" times"}' | sed ':a;N;$!ba;s/\n/ and on /g'`
echo "$emp presence on $DAYS "
done