1

如何使用带有 vi 的正则表达式替换每行中重复的单词字符串?例如,我有以下具有重复文本的海港列表。

我的目标是实现以下输出:

(输入)重复列表

Andorra La Vella Andorra La Vella
Al Ain Al Ain
Abu al Bukhoosh Abu al Bukhoosh
Ajman Ajman
Arzanah Island Arzanah Island
Abu Dhabi Abu Dhabi
Das Island Das Island
Al Dhafra Al Dhafra
Ras Zubbaya (Ras Dubayyah) Ras Zubbaya (Ras Dubayyah)
Dubai Dubai
Fateh Terminal Fateh Terminal
Fujairah (Al-Fujairah) Fujairah (Al-Fujairah)
Musafa Musafa
Hamriyah Hamriyah
Jebel Ali Jebel Ali
Jebel Dhanna Jebel Dhanna
Khor Al Fakkan Khor Al Fakkan
Masfut Masfut
Mubarras Island Mubarras Island

(输出)更正列表

Andorra La Vella
Al Ain
Abu al Bukhoosh
Ajman
Arzanah Island
Abu Dhabi
Das Island
Al Dhafra
Ras Zubbaya (Ras Dubayyah)
Dubai
Fateh Terminal
Fujairah (Al-Fujairah)
(...)

有什么见解吗?

( http://www.photius.com/seaports/中提供的端口的完整列表)

4

1 回答 1

5

对文件的每一行应用替换命令:

:%s/\v(.*)\s*\1/\1/

它产生:

Andorra La Vella 
Al Ain 
Abu al Bukhoosh 
Ajman 
Arzanah Island 
Abu Dhabi 
Das Island 
Al Dhafra 
Ras Zubbaya (Ras Dubayyah) 
Dubai 
Fateh Terminal 
Fujairah (Al-Fujairah) 
Musafa 
Hamriyah 
Jebel Ali 
Jebel Dhanna 
Khor Al Fakkan 
Masfut 
Mubarras Island
于 2013-09-30T09:57:59.077 回答