파일의 문장에서 중복 단어 제거 [duplicate]

Dec 08 2020

파일의 문장에서 중복 단어를 제거하려면 어떻게해야합니까? 각 문장은 별도의 줄로 작성됩니다.

감사합니다

파일에이 문장이 있습니다.

hello every body hello
word I should remove the word
how can can i remove it ?

예상되는 출력은

hello every body
word I should remove the
how can i remove it ?

답변

1 dawg Dec 08 2020 at 01:28

넌 할 수있어:

awk '{for(i=1;i<=NF;i++) if(++arr[$i]==1) print $i}' file

인쇄물:

hello
every
body
word
I
should
remove
the
how
can
i
it
?

라인 구조를 유지하려면

awk '{for(i=1;i<=NF;i++) 
       if(++arr[$i]==1) printf "%s%s", $i, OFS
       print ""}' file

인쇄물:

hello every body 
word I should remove the 
how can i it ? 

중복 제거가 라인 단위로만 수행되는 경우 :

awk '{delete arr
      for(i=1;i<=NF;i++) 
         if(++arr[$i]==1) printf "%s%s", $i, OFS
      print ""}' file

인쇄물:

hello every body 
word I should remove the 
how can i remove it ?