#!/bin/awk
BEGIN {
while(getline var < compareTo > 0)
{
orderIds[var]=var;
}
}
{
if(orderIds[$0] == "")
{
print $0;
}
}
다음으로 실행
awk -v compareTo="ids.log.remote" -f sample.awk ids.log.local
가능하지만 HashMap과 같은 연관 배열을 사용하는 대신 awk에 HashSet과 같은 것이 있습니까?
나한테 일정이 있어
bash-3.2$ time grep -xFvf ids.log.local ids.log.remote > /dev/null
real 0m0.130s
user 0m0.127s
sys 0m0.002s
bash-3.2$ time grep -xFvf ids.log.local ids.log.remote > /dev/null
real 0m0.126s
user 0m0.125s
sys 0m0.000s
bash-3.2$ time grep -xFvf ids.log.local ids.log.remote > /dev/null
real 0m0.131s
user 0m0.128s
sys 0m0.002s
bash-3.2$ time awk 'NR == FNR {
orderIds[$0]; next
}
!($0 in orderIds)
' ids.log.local ids.log.remote > /dev/null
real 0m0.053s
user 0m0.051s
sys 0m0.003s
bash-3.2$ time awk 'NR == FNR {
orderIds[$0]; next
}
!($0 in orderIds)
' ids.log.local ids.log.remote > /dev/null
real 0m0.052s
user 0m0.051s
sys 0m0.001s
bash-3.2$ time awk 'NR == FNR {
orderIds[$0]; next
}
!($0 in orderIds)
' ids.log.local ids.log.remote > /dev/null
real 0m0.053s
user 0m0.051s
sys 0m0.002s
bash-3.2$ time awk -v compareTo="ids.log.local" -f checkids.awk ids.log.remote > /dev/null
real 0m0.066s
user 0m0.060s
sys 0m0.006s
bash-3.2$ time awk -v compareTo="ids.log.local" -f checkids.awk ids.log.remote > /dev/null
real 0m0.065s
user 0m0.058s
sys 0m0.008s
bash-3.2$ time awk -v compareTo="ids.log.local" -f checkids.awk ids.log.remote > /dev/null
real 0m0.061s
user 0m0.053s
sys 0m0.007s
@Dimitre Radoulov awk가 더 빠른 것 같습니다. 감사해요.
답변1
나는 이것이 awk에서 가장 효율적인 방법이라고 생각합니다.
awk 'NR == FNR {
orderIds[$0]; next
}
!($0 in orderIds)
' ids.log.remote ids.log.local
grep을 시도해 볼 수도 있습니다.
grep -xFVf ids.log.remote ids.log.local