본문 바로가기

Linux

egrep ',11111,' test.txt | awk -F, '{print $3,$4}'| sort -u -k1 -k2 > result.txt

egrep ',11111,' test.txt | awk -F, '{print $3,$4}'| sort -u -k1 -k2 > result.txt

egrep ',11111,'  : ,11111,이 들어간 행 검색
awk -F, : ,를 기준으로 collum을 구분한다. 디폴트는 공백 이나 탭
'{print $3,$4}' : 3번째, 4번째 collum을 print
sort -u : 중복제거
sort -k2, -k1: 두번째 collum으로 정렬한 후 첫번째 collum으로 정렬
> 11111.txt : 파일에 출력

예)
------------------- test.txt ---------------------
test,11111,김경미,01011111111,test,test
test,11111,김경수,01011111112,test,test
test,11113,김경우,01011111113,test,test
test,11118,김경양,01011111114,test,test
test,11111,김경가,01011111115,test,test
test,11111,김경수,01011111111,test,test
test,11113,김경우,01011111110,test,test
test,11118,김경양,01011111112,test,test
test,11111,김경가,01011111185,test,test
--------------------------------------------------

egrep ',11111,' test.txt | awk -F, '{print $3,$4}'| sort -u -k1 -k2 > result.txt

------------------- result.txt ---------------------
김경가 01011111115
김경가 01011111185
김경미 01011111111
김경수 01011111111
김경수 01011111112
--------------------------------------------------