소스 검색

Add dedupe

master
JustAnotherArchivist 3 년 전
부모
커밋
4d274e64e0
1개의 변경된 파일15개의 추가작업 그리고 0개의 파일을 삭제
  1. +15
    -0
      dedupe

+ 15
- 0
dedupe 파일 보기

@@ -0,0 +1,15 @@
#!/bin/bash
function usage_exit {
echo 'Usage: dedupe FILE1 FILE2' >&2
echo >&2
echo 'Prints all lines from FILE2 that do not appear in FILE1, in the order of FILE2.' >&2
echo 'WARNING: FILE1 has to be read into memory fully. If your files are sorted, use comm instead.' >&2
exit $1
}

if [[ "$1" == '-h' || "$1" == '--help' ]]; then usage_exit 0; fi
if [[ $# -ne 2 ]]; then usage_exit 1; fi

# Perl seems to be ~30 % faster for this.
#awk 'NR==FNR { s[$0]=1; next; } !($0 in s)' "$1" "$2"
perl -ne 'if (@ARGV == 1) { $seen{$_}=1; } else { print $_ if !(exists $seen{$_}); }' "$1" "$2"

불러오는 중...
취소
저장