한 열과 비교해야하는 두 개의 csv 파일이 있습니다.
내 member.csv
파일은 다음과 같습니다.
ID|lastName|firstName
01|Lastname01|Firstname01
02|Lastname02|Firstname02
두 번째 파일 check-ID.csv
은 다음과 같습니다.
Lastname01|Name01|pubID01|Hash01
Lastname02|Name02|pubID02|Hash02a
Lastname03|Name03|pubID03|Hash03
Lastname02|Name02|pubID02|Hash02b
Lastname01|Name01|pubID01|Hash01b
-> Lastname03
내 member.csv
!
내가 원하는 것은의 첫 번째 열의 check-ID.csv
값이의 두 번째 열의 값과 같은지 확인하는 것입니다 member.csv
.
나의 시도 script.awk
는
NR==FNR{a[$1]=$1; b[$1]=$0; next}
$2==a[$1]{ delete b[$1]}
END{for (i in b ) print b[i]}
함께 실행
awk -f script.awk check-ID.csv member.csv
문제는 결과가 필터링되지 않는다는 것입니다.
필터링되고 정렬 된 출력을 얻고 싶으므로 멤버 만 다음과 같이 나열됩니다.
Lastname01|Name01|pubID01|Hash01
Lastname01|Name01|pubID01|Hash01b
Lastname02|Name02|pubID02|Hash02a
Lastname02|Name02|pubID02|Hash02b
어떤 도움을 주셔서 감사합니다!
다음을 시도해 주시겠습니까? 나는 당신이 당신의 Input_files 읽기 순서를 바꿀 수 있다는 것 뿐이라고 생각합니다. members
Input_file을 먼저 읽은 다음 check-ID.csv
나중에 Input_file에 인쇄해야하는 모든 세부 정보가 있으므로 Input_file 멤버의 두 번째 필드 만 확인하면됩니다.
awk '
BEGIN{
FS="|"
}
FNR==NR{
a[$2]
next
}
($1 in a)
' members.csv check-ID.csv |
sort -t'|' -k1
설명 : 위에 대한 자세한 설명을 추가합니다.
awk ' ##Starting awk program from here.
BEGIN{ ##Starting BEGIN section of this program from here.
FS="|" ##Setting field separator as | here.
}
FNR==NR{ ##Checking condition if FNR==NR which will be TRUE when first Input_file named members.csv is being read.
a[$2] ##Creating array a with index 2nd field here.
next ##next will skip all further statements from here.
}
($1 in a) ##Checking condition if 1st field is preent in a then print that line.
' members.csv check-ID.csv | ##Mentioning Input_file names here and sending its output to sort command.
sort -t'|' -k1 ##Sorting output(which we got from awk command above) by setting separator as | and by first field.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다