Remove consecutive duplicate words from a file using awk or sed

前端 未结 6 1422
不思量自难忘°
不思量自难忘° 2021-01-16 16:53

My input file looks like below:

“true true, rohith Rohith;
cold burn, and fact and fact good good?”

Output shoud look like:



        
6条回答
  •  长情又很酷
    2021-01-16 17:34

    sed -E 's/(\w+) *\1/\1/g' sample.txt
    

    sample.txt

    “true true, rohith Rohith;
    cold burn, and fact and fact good good?”
    

    output:

    :~$ sed -E 's/(\w+) *\1/\1/g' sample.txt
    “true, rohith Rohith;
    cold burn, and fact and fact good?”
    

    Explanation

    (\w) *\1 - matches a word separated by a space of the same word and saves it

提交回复
热议问题