Remove Duplicate Line in Vim?

后端 未结 9 1146
有刺的猬
有刺的猬 2021-01-15 06:19

I\'m trying to use VIM to remove a duplicate line in an XML file I created. (I can\'t recreate the file because the ID numbers will change.)

The file looks something

9条回答
  •  萌比男神i
    2021-01-15 07:10

    with python to remove all repeated lines:

    #!/usr/bin/env python
    
    import sys
    def remove_identical(filein, fileout) : 
      lines = list()
      for line in open(filein, 'r').readlines() : 
        if line not in lines : lines.append(line)
      fout = open(fileout, 'w')
      fout.write(''.join(lines))
      fout.close()
    
    remove_identical(sys.argv[1], sys.argv[2])
    

提交回复
热议问题