아래와 같이 두 개의 파일이 있습니다
파일 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