我有如下行的文本文件:this is the code ;rfc1234;rfc1234 this is the code ;rfc1234;rfc1234;rfc1234;rfc1234 如何将文件中的重复单词压缩为单个单词,如下所示:this is the code ;rfc1234 this is the code ;rfc1234 我试过tr命令,但只限于压缩字符 最佳答案 sed 's/\(;[^;]*\).*/\1/' file