Vi:仅删除非第一次(第二次、第三次)出现的多行
如何删除文本文件中除第一行之外的所有多行? (此问题可能相关。) 我需要保留顺序,否则我已经使用了 :sort u
。
示例:
hsdf
asdf
csdf
csdf
hsdf
dsdf
jsdf
asdf
结果
hsdf
asdf
csdf
dsdf
jsdf
代替
asdf
csdf
dsdf
hsdf
jsdf
How to delete every occurence of multiple lines in a text file except the first one? (This question might be related.)
I need to keep the order, otherwise I had used :sort u
.
Example:
hsdf
asdf
csdf
csdf
hsdf
dsdf
jsdf
asdf
results in
hsdf
asdf
csdf
dsdf
jsdf
instead of
asdf
csdf
dsdf
hsdf
jsdf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有时候你不需要想太多。只要拿起那把大锤子,敲一下就可以了。
那么计划是什么?循环所有行;将它们存储到关联数组中;如果它已经存在,则将其从缓冲区中删除。看起来很愚蠢,第一次尝试就能让事情发挥作用:
Sometimes you don't need to think much. Just take that big hammer and make a bang.
So what's the plan? Loop over all lines; store them into associative array; if it's already there then delete it from buffer. Looks dumb enough to get things working by the first attempt: